List the databases in a PostgreSQL instance
Published on 30 July 2019
I don’t feel like installing.https://www.pgadmin.org/[pgAdmin] ou phppgadmin while everything is present on the command line.
For that we need to launch the terminal and log in as the postgres user.
The postgres user is the only one who by default has the right to launch the psql application, which is the command-line client. </think>CLI) postgresql,
to be able to talk to the database from the command line in the terminal
To connect, launch the terminal and type this:
$ sudo -i -u postgres
To connect and go directly to the PostgreSQL command prompt, type this:
$ sudo -i -u postgres psql
To list the databases of a PostgreSQL instance, here is the command:
postgres=# \l
result:
List of databases Name | Owner | Encoding | Collation | Character Type | Access Privileges
fiber | tech | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =Tc/tech
| | | | | tech=CTc/tech fiberdev | tech | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =Tc/tech
| | | | | tech=CTc/tech fiberweb | tech | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =Tc/tech
| | | | | tech=CTc/tech postgres | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | template0 | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres
| | | | | postgres=CTc/postgres template1 | postgres | UTF8 | fr_FR.UTF-8 | fr_FR.UTF-8 | =c/postgres
| | | | | postgres=CTc/postgres (6 lines)
type q to exit the results display
to list the schemas of a postgresl instance
postgres=# SELECT schema_name FROM information_schema.schemata;
result
public information_schema pg_catalog pg_toast_temp_1 pg_temp_1 pg_toast (6 lignes)
ou
postgres=# SELECT nspname FROM pg_catalog.pg_namespace;
result
pg_toast pg_temp_1 pg_toast_temp_1 pg_catalog information_schema public (6 lines)