postgresql常用命令

\? #打印出所有跟\相关的命令

\h #打印出所有跟sql相关的命令

\h sql #查看具体sql相关的帮助,例如\h create user 是查看跟create user相关的帮助

\l #列出所有的数据库信息

\c #databasename #连接进入某个数据库

\d #查看当前数据库中所有表、视图、序列

\db #查看表空间的信息

\dn #查看所有的模式信息

\dg或者\du #查看数据库中所有的角色或用户

\dt #列出所有的表信息

\d tablename #查看某个表的结构

\du #查询数据库的用户信息

\x #设置查询结果的输出模式 (\x 竖行显示)

以反斜线开头的命令被称为元命令,如\db等。使用技巧如下:

1.获取元命令对一个的sql代码

需要在psql连接数据库时增加“-E”选项

2. 自动补全功能

使用tab键可以自动补全,例如要查询表department(select * from department),在输入“d”之后按tab键会自动出现department,再次按tab键,则会列出所有以d开头的表对象。

3.显示sql语句执行时间

使用"\timing"命令,可以打开显示sql语句执行时间的开关。可以再次使用一次"\timing"命令,则关掉该开关。

postgres=# \h

Available help:

ABORT CREATE FOREIGN DATA WRAPPER DROP ROUTINE

ALTER AGGREGATE CREATE FOREIGN TABLE DROP RULE

ALTER COLLATION CREATE FUNCTION DROP SCHEMA

ALTER CONVERSION CREATE GROUP DROP SEQUENCE

postgres=# \h alter AGGREGATE

Command: ALTER AGGREGATE

Description: change the definition of an aggregate function

Syntax:

ALTER AGGREGATE name ( aggregate_signature ) RENAME TO new_name

ALTER AGGREGATE name ( aggregate_signature )

OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }

ALTER AGGREGATE name ( aggregate_signature ) SET SCHEMA new_schema

where aggregate_signature is:

postgres=# select * from pg_tables; --查看所有的表信息

schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity

--------------------+-------------------------+------------+------------+------------+----------+-------------+-------------

pg_catalog | pg_statistic | postgres | | t | f | f | f

pg_catalog | pg_type | postgres | | t | f | f | f

pg_catalog | pg_foreign_table | postgres | | t | f | f | f

pg_catalog | pg_authid | postgres | pg_global | t | f | f | f

postgres=# select * from pg_tables where schemaname!='pg_catalog';

schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity

--------------------+-------------------------+------------+------------+------------+----------+-------------+-------------

information_schema | sql_parts | postgres | | f | f | f | f

information_schema | sql_implementation_info | postgres | | f | f | f | f

information_schema | sql_features | postgres | | f | f | f | f

information_schema | sql_sizing | postgres | | f | f | f | f

(4 rows)

postgres=#

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值