我有多个PostgreSQL-15数据库,具有不同的名称,以满足我们的业务运营数据,如:试点,生产和存档数据在不同的目的。
我正在尝试编写一个shell脚本,以检查每个表的所有者在不同的数据库下使用他们自己的表名。例如:
select tableowner from pg_catalog.pg_tables where schemaname = 'public' AND tablename = '$1' AND pg_database.datname = '$2';我的postgresql响应如下:
ERROR: missing FROM-clause entry for table "pg_database"我试图检索pg_catalog.pg_tables属性,发现属性中没有保存数据库信息。
我的问题是:如何通过在shell脚本中的单个psql语句中提供表名和数据库名来查询表属性,比如:
tableowner=`psql -h $prim_host -p $port -U postgres -t -c "select tableowner from pg_catalog.pg_tables where schemaname = 'public' AND tablename = '$1' AND pg_database.datname = '$2';"`请指点!
发布于 2023-05-25 03:59:51
您必须连接到包含表的数据库:
tableowner=$(psql -Atq -h $host -p $port -U postgres -d "$2" -c "SELECT relowner::regrole FROM pg_class WHERE relname = '$1'")https://dba.stackexchange.com/questions/327500
复制相似问题