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';
相关推荐
scheduleTTe8 小时前
SQL增查
数据库·sql
SoFlu软件机器人18 小时前
告别手动报表开发!描述数据维度,AI 自动生成 SQL 查询 + Java 导出接口
java·数据库·sql
云边散步21 小时前
🥢 第2篇:SELECT就是点菜,FROM就是菜单 —— 写你人生第一句SQL!
sql·mysql
见未见过的风景1 天前
想删除表中重复数据,只留下一条,sql怎么写
数据库·sql
hello 早上好2 天前
MyBatis 动态 SQL、#{}与 ${}区别、与 Hibernate区别、延迟加载、优势、XML映射关系
sql·mybatis·hibernate
NullPointerExpection2 天前
LLM大语言模型不适合统计算数,可以让大模型根据数据自己建表、插入数据、编写查询sql统计
数据库·人工智能·sql·算法·llm·llama·工作流
我命由我123452 天前
Spring Boot - Spring Boot 集成 MyBatis 分页实现 手写 SQL 分页
java·spring boot·后端·sql·spring·java-ee·mybatis
切糕师学AI2 天前
SQL中对字符串字段模糊查询(LIKE)的索引命中情况
数据库·sql
茅坑的小石头2 天前
SQL,在join中,on和where的区别
sql
云边散步2 天前
🧱 第1篇:什么是SQL?数据库是啥?我能吃吗?
数据库·sql