AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题

问题[psql](dba)

Martin Hope
toraritte
Asked: 2024-05-13 01:37:15 +0800 CST

如何对`psql`中元/斜杠命令的输出进行排序?

  • 5

例如,如何在 shell 本身中按“Column”中的值对下面的输出进行排序psql?

my_db=> \d auth_user
                                        Table "public.auth_user"
    Column    |           Type           | Collation | Nullable |                Default                
--------------+--------------------------+-----------+----------+---------------------------------------
 id           | integer                  |           | not null | nextval('auth_user_id_seq'::regclass)
 is_superuser | boolean                  |           | not null | 
 username     | character varying(150)   |           | not null | 
 first_name   | character varying(150)   |           |          | 
 last_name    | character varying(150)   |           | not null | 
 email        | character varying(254)   |           |          | 
 is_staff     | boolean                  |           | not null | false
 is_active    | boolean                  |           | not null | false
 password     | character varying(128)   |           |          | 
 last_login   | timestamp with time zone |           |          | 
 date_joined  | timestamp with time zone |           |          | 
Indexes:
    "auth_user_pkey" PRIMARY KEY, btree (id)
    "auth_user_username_6821ab7c_like" btree (username varchar_pattern_ops)
    "auth_user_username_key" UNIQUE CONSTRAINT, btree (username)

我知道这在 shell 之外很容易做到psql,例如在 Bash 中,

$ psql -U postgres -h localhost -d my_db -c '\d auth_user' | grep '^.*|' | sort -t'|' -k1

    Column    |           Type           | Collation | Nullable |                Default                
 date_joined  | timestamp with time zone |           |          | 
 email        | character varying(254)   |           |          | 
 first_name   | character varying(150)   |           |          | 
 id           | integer                  |           | not null | nextval('auth_user_id_seq'::regclass)
 is_active    | boolean                  |           | not null | false
 is_staff     | boolean                  |           | not null | false
 is_superuser | boolean                  |           | not null | 
 last_login   | timestamp with time zone |           |          | 
 last_name    | character varying(150)   |           | not null | 
 password     | character varying(128)   |           |          | 
 username     | character varying(150)   |           | not null | 

但我很好奇这是否可以完成psql。

psql
  • 2 个回答
  • 12 Views
Martin Hope
Disdainty
Asked: 2023-10-08 02:06:55 +0800 CST

在 ssh 环境中设置 Citus 扩展

  • 5

我尝试去做CREATE EXTENSION citus;。但是,我收到以下错误:

ERROR:  Citus can only be loaded via shared_preload_libraries
HINT:  Add citus to shared_preload_libraries configuration variable in postgresql.conf in master and workers. Note that citus should be at the beginning of shared_preload_libraries.

但是,我没有 root 访问权限。在这种情况下我该如何创建扩展?

我正在使用 PSQL 的源代码来设置数据库。这里有我可以修改以允许扩展的特定文件吗?

以下是我的源代码文件夹中的文件列表postgresql-15.3:

COPYRIGHT    GNUmakefile.in  INSTALL   README      config      config.status  configure.ac  doc
GNUmakefile  HISTORY         Makefile  aclocal.m4  config.log  configure      contrib       src
psql
  • 1 个回答
  • 17 Views
Martin Hope
frostzt
Asked: 2023-05-22 18:25:40 +0800 CST

在“psql”中使用“\dp table_name”抛出“运算符不是唯一的”

  • 8

问题

我试图跑\dp heroes进去,psql但它立即抛出了以下内容!(heroes是表名)

ERROR:  operator is not unique: unknown || "char"
LINE 16:            E' (' || polcmd || E'):'
                          ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.

我用谷歌搜索并找到了这些,但我不清楚到底发生了什么!
参考:https://www.postgresql.org/message-id/[email protected]

我试过什么!

尝试使用架构名称访问它也不起作用

\dp public.heroes;

初读时,我认为我必须投射它,但我认为我错了。

\dp heroes::"char";

额外的东西

顺便说一句,这是一个作为 docker 容器运行的 Postgres 实例。

这是它内部生成的查询:

SELECT n.nspname as "Schema",
  c.relname as "Name",
  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'S' THEN 'sequence' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' END as "Type",
  pg_catalog.array_to_string(c.relacl, E'\n') AS "Access privileges",
  pg_catalog.array_to_string(ARRAY(
    SELECT attname || E':\n  ' || pg_catalog.array_to_string(attacl, E'\n  ')
    FROM pg_catalog.pg_attribute a
    WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL
  ), E'\n') AS "Column privileges",
  pg_catalog.array_to_string(ARRAY(
    SELECT polname
    || CASE WHEN NOT polpermissive THEN
       E' (RESTRICTIVE)'
       ELSE '' END
    || CASE WHEN polcmd != '*' THEN
           E' (' || polcmd || E'):'
       ELSE E':'
       END
    || CASE WHEN polqual IS NOT NULL THEN
           E'\n  (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)
       ELSE E''
       END
    || CASE WHEN polwithcheck IS NOT NULL THEN
           E'\n  (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)
       ELSE E''
       END    || CASE WHEN polroles <> '{0}' THEN
           E'\n  to: ' || pg_catalog.array_to_string(
               ARRAY(
                   SELECT rolname
                   FROM pg_catalog.pg_roles
                   WHERE oid = ANY (polroles)
                   ORDER BY 1
               ), E', ')
       ELSE E''
       END
    FROM pg_catalog.pg_policy pol
    WHERE polrelid = c.oid), E'\n')
    AS "Policies"
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m','S','f','p')
  AND c.relname OPERATOR(pg_catalog.~) '^(heroes)$' COLLATE pg_catalog.default
  AND n.nspname OPERATOR(pg_catalog.~) '^(public)$' COLLATE pg_catalog.default
ORDER BY 1, 2;
psql
  • 1 个回答
  • 76 Views
Martin Hope
Nir
Asked: 2022-07-25 07:51:05 +0800 CST

psql 转义反斜杠

  • 0

我想逃避反斜杠,\b以便以后可以正常处理它。到目前为止,我使用了一个返回制表符分隔结果的命令,该结果也将空值转换\N为(对于 mysql load into):

PGPASSWORD=$PASS psql -qtAX -U $USER -h $HOST -p $PORT -d $DB -AF $'\t' -P 'null=\N'

有任何想法吗?

postgresql psql
  • 1 个回答
  • 60 Views
Martin Hope
nbari
Asked: 2022-02-11 03:47:31 +0800 CST

如何配置 psql 以使用不同的 unixsocket 路径

  • 1

我将 Postgres 的端口更改为,2345并且我的套接字位于:

/tmp/.s.PGSQL.2345

如果我运行,psql我会收到此错误:

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory

如何传递套接字路径?

postgresql psql
  • 1 个回答
  • 303 Views
Martin Hope
Dave
Asked: 2021-12-12 08:51:40 +0800 CST

在命令行上运行 COPY 命令时如何转义字符?

  • 0

我在 CentOS 7 上使用 Postgres 14。我想从 bash 脚本运行复制命令。我首先尝试在命令行上运行命令

$ PGPASSWORD=$DB_PASS psql -U $DB_USER -d $DB_NAME -c 'COPY myapp_currencyprice to STDOUT WITH (DELIMITER ",", FORMAT CSV, HEADER) \g /tmp/prices.csv'
ERROR:  syntax error at or near "\"
LINE 1: ...o STDOUT WITH (DELIMITER ",", FORMAT CSV, HEADER) \g /tmp/pr...

逃避分隔符的正确方法是什么?我试过改变我的单引号和双引号,但无济于事。

postgresql psql
  • 1 个回答
  • 711 Views
Martin Hope
PaxPrz
Asked: 2021-11-29 20:39:43 +0800 CST

Postgres仅列出用户的数据库并保持其他隐藏?

  • 0

我创建了一个 postgres 用户 'tester' 并允许只读到数据库A。该用户对数据库B & C没有权限。

但是当我\l列出数据库时。还列出了数据库B和C。如何只列出数据库A而隐藏其他数据库?

我在 pgadmin 中面临这个问题。我无法在 pgadmin 中进行编辑。我需要一种使用 postgres db 中的访问策略隐藏其他数据库的方法。

postgresql psql
  • 1 个回答
  • 767 Views
Martin Hope
j4nd3r53n
Asked: 2021-11-20 05:09:09 +0800 CST

psql:更改命令行编辑模式?

  • 2

psqlPostgreSQL CLI 使用 readline 作为它的用户界面。Readline 允许使用 emacs- 和 vi 两种编辑模式,并且psql默认使用 emacs 模式。另一方面,我将 vi 用于所有内容;是否有在 psql 中设置 vi 编辑模式的命令?

psql
  • 1 个回答
  • 107 Views
Martin Hope
showkey
Asked: 2021-11-17 01:03:06 +0800 CST

如何使用新创建的超级用户登录 postgres?

  • 0

我创建了一个新的超级用户

sudo su - postgres
createuser --interactive --pwprompt

名字是showkey,密码是xxxxxx。

postgres=# \du+
                                           List of roles
 Role name  |                         Attributes                         | Member of | Description 
------------+------------------------------------------------------------+-----------+-------------
 dbuser     |                                                            | {}        | 
 debian     |                                                            | {}        | 
 postgres   | Superuser, Create role, Create DB, Replication, Bypass RLS | {}        | 
 showkey    | Superuser, Create role, Create DB                          | {}        | 
 test_user1 |                                                            | {}        | 

现在我想登录showkey:

psql -U showkey  -W
Password: 
psql: error: FATAL:  Peer authentication failed for user "showkey"

如何使用新创建的超级用户登录 postgres ?

postgresql psql
  • 2 个回答
  • 222 Views
Martin Hope
alvarez
Asked: 2021-11-16 11:05:17 +0800 CST

PostgreSQL:如何列出内置 PUBLIC 角色的所有权限?

  • -1

文档说:

任何特定角色都将拥有直接授予它的权限、授予其当前成员的任何角色的权限以及授予 PUBLIC 的权限的总和。

如何从 psql CLI 中了解哪些权限授予 PUBLIC?

\du似乎列出了所有角色,但缺少 PUBLIC 行。我希望找出新创建的角色默认获得哪些权限会​​非常简单和直观。

postgresql psql
  • 1 个回答
  • 147 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve