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';
相关推荐
RestCloud8 小时前
借助ETL工具,实现AI智能体+数据的落地
数据仓库·人工智能·sql·etl·etlcloud·数据集成平台·java脚本
上海云盾-小余10 小时前
网站频繁遭遇 SQL 注入溯源与原生漏洞修复全流程总结
数据库·sql
_Jimmy_14 小时前
SQLAlchemy 复杂 SQL 执行指南与模板库
python·sql
2601_9549165916 小时前
ChatGPT 5.6 深度实践:用 AI 重构云成本治理体系,而不是简单“降本”
人工智能·sql·chatgpt·重构·测试用例
肖永威16 小时前
金仓数据库麒麟环境SQL终端使用入门实践(增删改查篇)
数据库·sql·金仓数据库
山峰哥17 小时前
数据库工程与SQL优化实战指南‌
数据库·sql·oracle·深度优先·宽度优先
观远数据1 天前
ChatBI选型对比:从意图识别到SQL修复,六个维度打分决定是否值得投产
数据库·人工智能·sql
嘉&年华1 天前
【第008篇】通过dexp和dimp命令导出和导入dmp文件(适用于达梦数据库)
数据库·sql
xieliyu.2 天前
MySQL 六大基础约束详解:NOT NULL/DEFAULT/UNIQUE/ 主键 / 外键 / CHECK
android·数据库·sql·mysql
Anokata2 天前
MYSQL SQL 执行系列1
android·sql·mysql