PostgreSQL psqlterminal命令

我试图让psql格式很好,并在这里跟随文档。 现在,每当我对有很多列的表进行查询时,无论我的屏幕有多大,每行都会溢出到下一行,并产生整个屏幕上不可读的垃圾。

文档(链接在上面)说,有一种方法可以很好地alignment列以获得更多可读的输出。

通常,要启动psql ,只需键入:

PSQL

并按Enter键 。 现在我试着:

psql \ pset格式alignment

并得到一个错误:

 could not change directory to "/root" psql: warning: extra command-line argument "aligned" ingored psql: FATAL: Indent authentication failed for user "format" 

任何想法,我怎么能得到这些命令行参数为我工作?

这些不是命令行参数。 运行psql。 pipe理login到数据库(如果需要,传递主机名,端口,用户和数据库)。 然后写在p​​sql程序中。

示例(下面是两个命令,写入第一个命令,按回车,等待psqllogin,写入第二个命令):

 psql -h host -p 5900 -U username database \pset format aligned 

使用\x来自postgres手册的示例:

  postgres=# \x postgres=# SELECT * FROM pg_stat_statements ORDER BY total_time DESC LIMIT 3; -[ RECORD 1 ]------------------------------------------------------------ userid | 10 dbid | 63781 query | UPDATE branches SET bbalance = bbalance + $1 WHERE bid = $2; calls | 3000 total_time | 20.716706 rows | 3000 -[ RECORD 2 ]------------------------------------------------------------ userid | 10 dbid | 63781 query | UPDATE tellers SET tbalance = tbalance + $1 WHERE tid = $2; calls | 3000 total_time | 17.1107649999999 rows | 3000 -[ RECORD 3 ]------------------------------------------------------------ userid | 10 dbid | 63781 query | UPDATE accounts SET abalance = abalance + $1 WHERE aid = $2; calls | 3000 total_time | 0.645601 rows | 3000 
 psql --pset=format=FORMAT 

非常适合从命令行执行查询,例如

 psql --pset=format=unaligned -c "select bandanavalue from bandana where bandanakey = 'atlassian.confluence.settings';" 

从windows-7命令行连接到postgresql v9.3服务器的步骤如下 –

 1. Go to the start --> All programs --> postgresql 9.3 --> Sql Shell (psql) 2. Just enter the details requested by postgres server, I've shown log snippet from my CMD. 

(注意:“postgres”用户将是postgresql服务器的超级用户,密码应该是您在安装postgresql期间input的密码)

 Server [localhost]: localhost Database [postgres]: postgres Port [5432]: 5432 Username [postgres]: postgres Password for user postgres: psql (9.3.5) WARNING: Console code page (437) differs from Windows code page (1252) 8-bit characters might not work correctly. See psql reference page "Notes for Windows users" for details. Type "help" for help. postgres=# CREATE ROLE prateek LOGIN PASSWORD 'test_123' NOINHERIT CREATEDB; CREATE ROLE postgres=#