当前位置:网站首页>SQL knowledge summary 004: Postgres terminal command summary

SQL knowledge summary 004: Postgres terminal command summary

2022-07-08 00:05:00 Cloth scholar Python

I am using postgresql Container created postgresql database , Therefore, the following commands are based on this !

1. Enter into container :

docker exec -it  Containers id  /bin/bash

2. Command line login database , Enter the database created by default :

The format is :

psql -U username -h ipaddress -d dbname

My is :

psql -U postgres -d postgres

3. List all databases :

postgres=# \l

 Insert picture description here

4. Switch database :

postgres=# \c tododb

among ,tododb Is my other database name

5. List the tables under the current database

Because my database only has postgres There's data in , therefore , First use \c Switch back , Reuse \d View all tables in the database :

postgres=# \d

 Insert picture description here

6. Show current database

postgres=# select current_database()

7. List all the fields of the table

postgres=# \d tablename

8. Check the basic information of the table

postgres=# \d+ tablename

9. Change database password :

alter user postgres with password '654321';

Note that the password is ’ ‘ Enclosed content ! Don't lose the last ; Number , Otherwise nothing can be done .

It's also easy to change the password expiration time :

alter user postgres with valid until '2017-01-01 08:00:00';

If you want to change it to never expire :

alter user postgres with valid until 'infinity';

10. Log out

postgres=# \q
原网站

版权声明
本文为[Cloth scholar Python]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130552292798.html