Today I lost way too much time trying to understand why I couldn’t see data in a PostgreSQL database running inside a Docker container. I was connected via DBeaver, everything looked fine:

  • connection successful
  • schemas visible
  • but no tables

At some point I stopped guessing and went back to basics: the PostgreSQL console. The command like this I had to enter in PowerShell. Also you can find this link in Docker Desktop in the tab Exec.

docker exec -it <container_name> /bin/sh

docker exec -it 87c8b16d3474ed04f1d0746ff4d96a248a33447960dc9a925a29fac56b020246 /bin/sh

To connect to Postgresql use this command:

psql -h 127.0.0.1 -p 5432 -U username -d databasename
psql -h 127.0.0.1 -p 5432 -U alex -d alex

Get the list of databases

\list or \l: list all databases
\list

The result looks like this

                                                 List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+-------+----------+-----------------+------------+------------+--------+-----------+-------------------
alex | alex | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
postgres | alex | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
template0 | alex | UTF8 | libc | en_US.utf8 | en_US.utf8 | | | =c/alex +
| | | | | | | | alex=CTc/alex
template1 | alex | UTF8 | libc | en_US.utf8 | en_US.utf8 | | | =c/alex +
| | | | | | | | alex=CTc/alex
(4 rows)

Connect to a certain database

\c : connect to a certain database
\с alex (alex - database name)

Get the list of the tables in the database

\dt: list all tables in the current database using your search_path

The result looks like this

                 List of tables
Schema | Name | Type | Owner
--------+-----------------------+-------+-------
public | Abb_RoleClaims | table | alex
public | Abb_Roles | table | alex
public | Abb_UserClaims | table | alex
public | Abb_UserLogins | table | alex
public | Abb_UserRoles | table | alex
public | Abb_UserTokens | table | alex
public | Abb_Users | table | alex
public | BankOperations | table | alex
public | Blogs | table | alex
public | Categories | table | alex
public | Countdowns | table | alex
public | SiteRequests | table | alex
public | WordCollections | table | alex
public | WordHistories | table | alex
public | __EFMigrationsHistory | table | alex
(15 rows)