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';
相关推荐
Lx3521 小时前
LIKE查询中索引有效利用的前缀匹配策略
后端·sql·oracle
岁忧2 小时前
LeetCode 高频 SQL 50 题(基础版)之 【高级字符串函数 / 正则表达式 / 子句】· 上
sql·算法·leetcode
bbsh20993 小时前
WebFuture 升级提示“不能同时包含聚集KEY和大字段””的处理办法
数据库·sql·mysql·webfuture
刘 大 望12 小时前
数据库-联合查询(内连接外连接),子查询,合并查询
java·数据库·sql·mysql
cookqq15 小时前
mongodb源码分析session异步接受asyncSourceMessage()客户端流变Message对象
数据库·sql·mongodb·nosql
斯特凡今天也很帅16 小时前
clickhouse常用语句汇总——持续更新中
数据库·sql·clickhouse
海尔辛21 小时前
SQL 基础入门
数据库·sql
噼里啪啦啦.1 天前
Spring事务和事务传播机制
数据库·sql·spring
李少兄1 天前
解决 idea提示`SQL dialect is not configured` 问题
java·sql·intellij-idea
珹洺1 天前
数据库系统概论(十七)超详细讲解数据库规范化与五大范式(从函数依赖到多值依赖,再到五大范式,附带例题,表格,知识图谱对比带你一步步掌握)
java·数据库·sql·安全·oracle