Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

tcpdump - Sniffing Django database query packets

I'm not sure if this is the good place to ask this type of question.

I have the following set up:

DB_HOST=localhost
DB_PORT=5432


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ["DB_NAME"],
        'USER': os.environ["DB_USER"],
        'PASSWORD': os.environ["DB_PASS"],
        'HOST': os.environ["DB_HOST"],
        'PORT': os.environ["DB_PORT"],
    },
}

and was able run a query and get the data back:

 >>> from app1.models import Facility
 >>> facility = Facility.objects.filter(id=32432148)
 >>> print("NAME:"+facility[0].algo_name)
 NAME:FBNR_LE
 >>> print("FAC_ID:"+facility[0].fac_id)
 FAC_ID:FBNR_LE_BNS

What I want to do is to bascally sniff the DB query packets sent from Django over to Postgresql server.

So I run tcpdump for duration of the query:

# tcpdump 'tcp port 5432' -w /tmp/tcp_dump.pcap

However, the query and the data returned from it can not be found in the output file. Anyone have idea how I can capture and view Django query packets?

question from:https://stackoverflow.com/questions/65941419/sniffing-django-database-query-packets

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...