Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 以下命令:- psql \l \c database_name_Postgresql - Fatal编程技术网

Postgresql 以下命令:- psql \l \c database_name

Postgresql 以下命令:- psql \l \c database_name,postgresql,Postgresql,如果还要检查数据库的大小,请使用:- \l+ 按q返回 找到数据库后,现在可以使用以下命令连接到该数据库:- psql \l \c database_name 连接后,您可以通过以下方式检查数据库表或架构:- \d 现在返回到shell使用:- q 现在,要进一步了解某个表的详细信息,请使用:- \d table_name 要返回postgresql\u shell,请按\q 要返回到终端,请按退出以查看psql中的外部表,快速运行 # just list all the post

如果还要检查数据库的大小,请使用:-

\l+
q
返回

找到数据库后,现在可以使用以下命令连接到该数据库:-

psql
\l
\c database_name
连接后,您可以通过以下方式检查数据库表或架构:-

\d
现在返回到shell使用:-

q
现在,要进一步了解某个表的详细信息,请使用:-

\d table_name
要返回postgresql\u shell,请按
\q


要返回到终端,请按退出以查看psql中的外部表,快速运行

# just list all the postgres tables sorted in the terminal
db='my_db_name'
clear;psql -d $db -t -c '\dt'|cut -c 11-|perl -ne 's/^([a-z_0-9]*)( )(.*)/$1/; print'
或者,如果您更喜欢更清晰的json输出多行程序:

IFS='' read -r -d '' sql_code <<"EOF_CODE"
    select array_to_json(array_agg(row_to_json(t))) from (
        SELECT table_catalog,table_schema,table_name 
        FROM information_schema.tables
        ORDER BY table_schema,table_name ) t
EOF_CODE
psql -d postgres -t -q -c "$sql_code"|jq

IFS=''read-r-d''sql\u code在命令行中列出所有表的最简单的方法是,我喜欢:

psql -a -U <user> -p <port> -h <server> -c "\dt"
psql-a-U-p-h-c“\dt”
对于给定的数据库,只需添加数据库名称:

psql -a -U <user> -p <port> -h <server> -c "\dt" <database_name>
psql-a-U-p-h-c“\dt”

它可以在Linux和Windows上运行。

此SQL查询适用于大多数版本的PostgreSQL,并且相当简单

select table_name from information_schema.tables where table_schema='public' ;
  • 登录后,在PostgreSQL命令行界面中,键入以下命令以连接所需的数据库

        \c [database_name]
    
  • 然后您将看到此消息
    您现在已连接到数据库“[数据库名称]”

  • 键入以下命令以列出所有表

        \dt
    

  • @StephenCorwin No,
    \l
    相当于MySQL中的
    显示数据库<代码>dt
    ≃ <代码>显示表格
    l
    ≃ <代码>显示数据库
    \dt
    非常有用。pg_目录。pg_表一个要小得多,因为它似乎将内部表与用户创建的表合并在一起,用于您碰巧连接到的任何数据库。
    psql my_db_name
    应该运行,以便
    \dt
    工作。当我在没有数据库名称的情况下运行
    psql
    时,我得到了一条没有系统表的“找不到关系”消息:
    SELECT*FROM pg_catalog.pg_tables WHERE schemaname!='pg_目录和方案名称!='信息\u schema'
    您首先需要
    \c
    来选择您的数据库。+1虽然为了完整起见,mysql show tables只显示当前的模式,但这样想很好,mysql只有一个数据库,但有多个模式,其中postgresql可以有多个数据库(目录)和模式。因此,等价物应该是table_schema='DB_NAME';不完全是标准sql,无法使用“| |”连接上的字符串mssql@ChRoNoN:这是标准SQL
    | |
    自1983年以来一直是SQL标准中的字符串连接运算符-使用非标准字符串连接运算符的是MS SQL。我不确定这是否回答了问题。我认为OP试图知道数据库中的所有表,而不是从数据库中的特定表中获取所有行。。。对吗?顺便说一句,TOAST用来存储大值:我很确定你把
    +
    S
    搞混了。后者(字母)显示模式表。
    +
    只是显示了额外的信息。请参见不要发布重复的答案。答案不重复。有小改动。这直接给出了表格名称,我试图编辑原始答案,但未获得批准,因此给出了一个有效的答案。答案由Milen A.Radev提供表格名称。Reynante Daitol的答案包含了这段代码的其余部分。如果您认为这段代码提供了一些新的和独特的东西,那么就有理由包含一个解释来指出这一点。在没有解释的情况下,人们只能猜测它为何不同或可能更好。“psql-U postgres”将记录并连接到“postgres”数据库
    sudo -u postgres psql
    
    psql -U postgres
    psql --username=postgres
    
    psql mydb
    
    \dt myschema.*
    
                   List of relations
     Schema   |       Name      | Type  |  Owner   
    ----------+-----------------+-------+----------
     myschema | users           | table | postgres
     myschema | activity        | table | postgres
     myschema | roles           | table | postgres
    
    SELECT c.relname AS Tables_in FROM pg_catalog.pg_class c
            LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    WHERE pg_catalog.pg_table_is_visible(c.oid)
            AND c.relkind = 'r'
            AND relname NOT LIKE 'pg_%'
    ORDER BY 1
    
    sudo su - postgres
    
    psql
    
    \l
    
    \l+
    
    \c database_name
    
    \d
    
    q
    
    \d table_name
    
    # just list all the postgres tables sorted in the terminal
    db='my_db_name'
    clear;psql -d $db -t -c '\dt'|cut -c 11-|perl -ne 's/^([a-z_0-9]*)( )(.*)/$1/; print'
    
    IFS='' read -r -d '' sql_code <<"EOF_CODE"
        select array_to_json(array_agg(row_to_json(t))) from (
            SELECT table_catalog,table_schema,table_name 
            FROM information_schema.tables
            ORDER BY table_schema,table_name ) t
    EOF_CODE
    psql -d postgres -t -q -c "$sql_code"|jq
    
    psql -a -U <user> -p <port> -h <server> -c "\dt"
    
    psql -a -U <user> -p <port> -h <server> -c "\dt" <database_name>
    
    select table_name from information_schema.tables where table_schema='public' ;
    
        \c [database_name]
    
        \dt