Answer the question
In order to leave comments, you need to log in
How can I find out if I am connecting to the correct PostgreSQL database?
Good day everyone!
For the Django (Python web framework) project, I decided to use a new PostgreSQL database for myself.
Created a database and made it the owner of the newly created user dbuser, who was given a password.
I registered in the Django project settings (everything seems to be correct here):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'ew',
'USER': 'dbuser',
'PASSWORD': '...',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
postgres=# SHOW hba_file;
hba_file
--------------------------------------
/etc/postgresql/9.3/main/pg_hba.conf
(1 row)
[email protected]:/home/WMUser/ew$ psql -U dbuser -d ew
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "ru_RU.UTF-8",
LC_ADDRESS = "ru_RU.UTF-8",
LC_MONETARY = "ru_RU.UTF-8",
LC_NUMERIC = "ru_RU.UTF-8",
LC_TELEPHONE = "ru_RU.UTF-8",
LC_IDENTIFICATION = "ru_RU.UTF-8",
LC_MEASUREMENT = "ru_RU.UTF-8",
LC_TIME = "ru_RU.UTF-8",
LC_NAME = "ru_RU.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Password for user dbuser:
psql (9.3.8)
Type "help" for help.
ew=>
ew=> \dt
No relations found.
[email protected]:~/ew/eworld$ python manage.py dbshell
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "ru_RU.UTF-8",
LC_ADDRESS = "ru_RU.UTF-8",
LC_MONETARY = "ru_RU.UTF-8",
LC_NUMERIC = "ru_RU.UTF-8",
LC_TELEPHONE = "ru_RU.UTF-8",
LC_IDENTIFICATION = "ru_RU.UTF-8",
LC_MEASUREMENT = "ru_RU.UTF-8",
LC_TIME = "ru_RU.UTF-8",
LC_NAME = "ru_RU.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
psql (9.3.8, server 9.3.3)
Type "help" for help.
ew=> \dt
List of relations
Schema | Name | Type | Owner
--------+----------------------------+-------+--------
public | auth_group | table | dbuser
public | auth_group_permissions | table | dbuser
public | auth_permission | table | dbuser
public | auth_user | table | dbuser
public | auth_user_groups | table | dbuser
public | auth_user_user_permissions | table | dbuser
public | django_admin_log | table | dbuser
public | django_content_type | table | dbuser
public | django_migrations | table | dbuser
public | django_session | table | dbuser
(10 rows)
ew=>
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
ew | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | dbuser=CTc/postgres
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
ew | dbuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
Answer the question
In order to leave comments, you need to log in
Most likely, django connects via a tcp socket, and psql connects locally; try specifying a host to connect to:psql -U dbuwer -H 127.0.0.1 ew
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question