PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Come disconnettersi da un database e tornare al database predefinito in PostgreSQL?

È facile, basta guardare l'esempio.

--i miei database

postgres=# \l
                               List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |     Access privileges     
-----------+----------+----------+---------+-------+---------------------------
 francs    | postgres | UTF8     | C       | C     | =Tc/postgres             +
           |          |          |         |       | postgres=CTc/postgres    +
           |          |          |         |       | francs=C*T*c*/postgres   +
           |          |          |         |       | select_only=c/francs
 postgres  | postgres | UTF8     | C       | C     | 
 source_db | postgres | UTF8     | C       | C     | =Tc/postgres             +
           |          |          |         |       | postgres=CTc/postgres    +
           |          |          |         |       | source_db=C*T*c*/postgres
 template0 | postgres | UTF8     | C       | C     | =c/postgres              +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres              +
           |          |          |         |       | postgres=CTc/postgres
(5 rows)

--passa ai franchi db come franchi di ruolo

postgres=# \c francs francs
You are now connected to database "francs" as user "francs".

--passa a db postgres come ruolo postgres

francs=> \c postgres postgres

You are now connected to database "postgres" as user "postgres".
postgres=# 

--disconnetti da db

postgres=# \q