linux 进入psql终端,PostgreSQL psql终端命令(PostgreSQL psql terminal command)

PostgreSQL psql终端命令(PostgreSQL psql terminal command)

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

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

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

PSQL

并按Enter键 。 现在我试着:

psql \ pset格式对齐

并得到一个错误:

could not change directory to "/root"

psql: warning: extra command-line argument "aligned" ingored

psql: FATAL: Indent authentication failed for user "format"

关于如何让这些命令行参数适合我的任何想法?

I'm trying to get psql to format nicely and am following the docs here. Right now, whenever I do a query on tables with lots of columns, no matter how big I make my screen each line overflows into the next line and producing a whole screen of unreadable junk.

The docs (link is above) say there's a way to align columns nicely for more readable output.

Normally, to start psql, I just type:

psql

and hit Enter. Now I'm trying:

psql \pset format aligned

And getting an error:

could not change directory to "/root"

psql: warning: extra command-line argument "aligned" ingored

psql: FATAL: Indent authentication failed for user "format"

Any ideas as to how I could get these command-line args to work for me?

原文:https://stackoverflow.com/questions/8990098

更新时间:2019-10-28 00:02

最满意答案

这些不是命令行参数。 运行psql。 管理登录到数据库(如果需要,传递主机名,端口,用户和数据库)。 然后将其写入psql程序中。

示例(下面是两条命令,写入第一条命令,按回车,等待psql登录,写入第二条命令):

psql -h host -p 5900 -U username database

\pset format aligned

These are not command line args. Run psql. Manage to log into database (so pass the hostname, port, user and database if needed). And then write it in the psql program.

Example (below are two commands, write the first one, press enter, wait for psql to login, write the second):

psql -h host -p 5900 -U username database

\pset format aligned

2012-01-24

相关问答

这些不是命令行参数。 运行psql。 管理登录到数据库(如果需要,传递主机名,端口,用户和数据库)。 然后将其写入psql程序中。 示例(下面是两条命令,写入第一条命令,按回车,等待psql登录,写入第二条命令): psql -h host -p 5900 -U username database

\pset format aligned

These are not command line args. Run psql. Manage to log into database (so pass

...

非常感谢Craig Ringer ,作品,最后作品! 你现在是我的新偶像! 步骤是: 打开cmd SET PGCLIENTENCODING = utf-8 chcp 65001 psql -h 192.168.114.12 -U postgres Thanks a lot Craig Ringer, works, finally works! You are my new idool now! The steps are: open the cmd SET PGCLIENTENCODING=utf

...

psql如果在没有任何参数的情况下默认运行,则会获取当前用户名,这显然不存在,因为您刚刚安装了postgresql。 另一方面,ubuntu的postgresql发行版附带了一个默认的postgres用户(在系统和postgresql数据库中都有)。 这意味着如果您代表postgres用户运行psql命令,那么您将能够连接: sudo -u postgres psql

psql if run by default without any arguments takes the current u

...

问题是psql不会跳过文件的第一行。 你可以试试 #! /bin/sh

exec sh -c "tail -n +3 $0 | psql -f -"

select now();

或干脆 #! /bin/sh

psql << E_O_SQL

select now();

E_O_SQL

The problem is that psql don't skip the first line of the file. You could try #! /bin/sh

exec sh -c "tai

...

键入\q ,然后按ENTER退出psql 。 Type \q and then press ENTER to quit psql. UPDATE: 19-OCT-2018 As of PostgreSQL 11, the keywords "quit" and "exit" in the PostgreSQL command-line interface have been included to help make it easier to leave the command-line tool

...

从你的描述我想你有hba文件中的同行认证。 要检查它与psql(你的sudo -u postgres方法)连接到db和: t=# show hba_file ;

hba_file

---------------------

/pg/d10/pg_hba.conf

(1 row)

t=# \! grep local /pg/d10/pg_hba.conf | grep -v "#"

local all all

...

你可以使用encode功能: select encode(bytea_column, 'hex')

from image;

如果您只想查看第一个字节,只需使用left()函数即可: select left(encode(bytea_column, 'hex'), 40)

from image;

手册中的更多细节: http://www.postgresql.org/docs/current/static/functions-binarystring.html you can use the e

...

请在此处发布相关消息: /postgres/server.log和psql --version 。 如果在server.log内部是这样的,请阅读下一步。 致命错误:预先存在的共享内存块(密钥5432001,ID 65538)仍在使用中提示:如果您确定没有旧服务器进程仍在运行,请删除共享内存块或只删除文件“postmaster.pid” 。 如果您的postrgres中没有关键数据,您可以立即尝试此修复: /etc/init.d/postgresql stop (如果某些进程正在运行,请尝试和平关

...

以用户postgres(或具有必要权限的任何其他用户)在数据库服务器的shell中运行: postgres@db:~$psql

CREATE DATABASE mydb;

\c mydb

\i /path/to/backup.sql

因此,您创建一个数据库,连接到它并从该文件运行纯文本SQL脚本以还原内容。 手册中有关psql的详细信息。 Run in a shell of your database server as user postgres (or any other us

...

这是一种帮助隔离您可能遇到的问题的方法。 步骤1:查看是否可以在不使用Bash点文件的情况下将PostgreSQL添加到PATH中。 $ export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;

$ which psql

如果这样可行...... 步骤2:验证在启动新用户会话时是否获取~\.bash_profile 。 将以下内容添加到~/.bash_profile的末尾: echo "From bash_profile."

...

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值