pgsql基本操作

查看已经存在的数据库

复制代码
postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | 
 runoobdb  | postgres | UTF8     | C       | C     | 
(4 rows)

进入数据库:

复制代码
postgres=# \c runoobdb
You are now connected to database "runoobdb" as user "postgres".

连接数据库

复制代码
$ psql -h localhost -p 5432 -U postgres runoobdb
Password for user postgres: ****
psql (11.3)
Type "help" for help.
You are now connected to database "runoobdb" as user "postgres".
runoobdb=# 

删除数据库

复制代码
postgres=# DROP DATABASE runoobdb;	

查看所有表

复制代码
\d

查看表信息

复制代码
runoobdb=# \d company
                  Table "public.company"
 Column  |     Type      | Collation | Nullable | Default 
---------+---------------+-----------+----------+-------

删除表

复制代码
runoobdb=# drop table department

12.PostgreSQL 导出数据库:(以数据库名为work_face为例)

复制代码
pg_dump -h 127.0.0.1 -p 5432 -U postgres -d work_face  -Fc -f C:\Users\admin\Desktop\work_face.dmp 

PostgreSQL 导入数据库:(以数据库名为work_face为例)

复制代码
pg_restore -h 127.0.0.1 -U postgres -d work_face C:\Users\admin\Desktop\work_face.dmp

查看当前活动

复制代码
SELECT  pid,  usename AS username,  datname AS database_name,  application_name AS application,  state,  query FROM  pg_stat_activity;

查看指定表索引信息

复制代码
SELECT    indexname AS index_name,    indexdef AS index_definition FROM pg_indexes WHERE tablename = 'event_log';
相关推荐
BD_Marathon1 天前
SQL学习指南——视图
数据库·sql
2601_962072551 天前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
HackTwoHub1 天前
Sqli-Scanner SQL注入SKILL自动化挖掘SQL注入,零依赖自动化SQL注入挖掘,赏金猎人
数据库·人工智能·sql·web安全·网络安全·自动化·系统安全
Volunteer Technology1 天前
Flink Table API与SQL(一)
大数据·sql·flink
持敬chijing1 天前
Web渗透之SQL注入-常用sql语句
sql·安全·web安全·网络安全
Theo·Chan1 天前
更换 Kingbase V9 License 踩坑记
sql·信创·kingbase
yangshicong2 天前
第16章:AI数据分析与Text-to-SQL
人工智能·python·sql·数据分析·langchain
Chengbei112 天前
AISec真正拟人化全自动渗透工具!支持浏览器交互全自动化挖掘,SQL注入、XSS、越权等。
sql·安全·web安全·网络安全·自动化·系统安全·xss
审判长烧鸡2 天前
数据库字段命名规范速查表
数据库·sql
吴声子夜歌2 天前
SQL经典实例——元数据查询
数据库·sql