博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
psql 常用命令
阅读量:2342 次
发布时间:2019-05-10

本文共 2439 字,大约阅读时间需要 8 分钟。

1) psql common commands

1-1) Connect to postgresql database

psql -d dbname -U username -h host "sslmode=require" -W

1-2) Switch connection to a new database

if you omit the user parameter, the current user is assumed.

\c dbname username

1-3) List available databases

To list all database in the current PostgreSQL database server

\list \l      # shortcut

1-4) List available tables

To list all tables in the current database

\dt

1-5) Describe a table

To describe a table such as a column, type, modifiers of columns, etc…

\d table_name

1-6) List available schema

To list all schema of the currently connected database,

\dn

1-7) List available functions

To list all functions in the current database

\df

1-8) List available views

To list all views in the current database

\dv

1-9) List users and their roles

To list all users and their assign roles

\du

1-10) Execution the previous command

To retrieve the current version of PostgreSQL server

select version();

Now, you want to save time typing the previous command again, you can use \g command to execution the previous command

\g

1-11) Command history

To display command history

\s

if you want to save the command history to a file , you need to specify the file name followed the \s command as follows:

\s filename

1-12) Execution sql commands from a file

\i filename

1-13) Get help on psql command

To know all available psql command, you use the \? command:

\?

To get help on specific PostgreSQL statement, you use the following command:

\h alter table

1-14) Turn on query execution time

To turn on query execution time, you use the following command:

\timing

you use the same command to turn it off.

1-15) Edit command in your own editor

It is very handy if you can type the command in your favorite editor. To do this in psql, you \e command. After issuing the command, psql will open the text editor defined by your EDITOR environment variable and place the most recent command that you entered in psql into the editor.

\e

After you type the command in the editor, save it and close the editor, psql will execute the command and return the result.

It is more useful when you edit a function in the editor:

\ef [function name]

Switch output options

psql supports some type of output format and allows your to customize how to output is formatted on fly:

\a # command switches from aligned to non-aligned column output\H # command formats the output to HTML format.

1-16) Quit psql

\q

转载地址:http://ehyvb.baihongyu.com/

你可能感兴趣的文章
Redis,API的理解和使用-全局命令
查看>>
shell之eval
查看>>
postgresql基本操作
查看>>
SQLAlchemy使用
查看>>
word设置标题
查看>>
git之HEAD
查看>>
基于2.6内核的Init_task进程之一
查看>>
C代码插入汇编
查看>>
C++基础知识-之强指针(韦东山视频学习)
查看>>
C++之Android弱指针
查看>>
C++基础知识之vector和[=] [&] [=,&]拷贝
查看>>
C语言常见错误
查看>>
Init中的next_token()函数
查看>>
STL之MAP和Vector
查看>>
智能指针 unique_ptr
查看>>
Init.rc配置文件Action字段解析
查看>>
uml问题解决
查看>>
cpu结构框图
查看>>
mmap内存映射和shmget共享内存
查看>>
c中int和long类型
查看>>