返回 Discover
Field DispatchStack Overflow8 · 2026-06-01

How to show tables in PostgreSQL?

Tags
databasepostgresqlcommanddatabase-tabledbtable
Score
2,647
Answers
28
Views
3,407,024
Answered
Yes
Accepted
Yes
痛点分析发布于 2026/05/31

痛点为 AI 基于上游原始证据的初步提炼;未包含额外中国市场检索。

痛点

用户在从 MySQL 迁移到 PostgreSQL 时,需要快速找到列出所有表的等效命令,但 PostgreSQL 的语法和工具与 MySQL 差异较大,导致用户必须中断当前工作去搜索或查阅文档。Stack Overflow 上该问题获得 2647 分、340 万次浏览和 28 个回答,说明大量用户反复遇到这一基础操作障碍。这种摩擦不仅浪费开发者的时间,还增加了学习成本和上下文切换的认知负担,尤其在紧急排查或脚本编写场景下会显著降低效率。

§ Dossier

Stack Overflow question

What's the equivalent to show tables (from MySQL) in PostgreSQL?

§ Dossier

Question details

View count
3,407,024
Answer count
28
Last activity
2025/02/07
§ Dossier

Answers

From the psql command line interface, First, choose your database \c database_name Then, this shows all tables in the current schema: \dt Programmatically (or from the psql interface too, of course): SELECT * FROM pg_catalog.pg_tables; The system tables live in the pg_catalog database.

评论作者信息不可用Accepted3,769 votes

You can use PostgreSQL's interactive terminal Psql to show tables in PostgreSQL. 1. Start Psql Usually you can run the following command to enter into psql: psql DBNAME USERNAME For example, psql template1 postgres One situation you might have is: suppose you login as root, and you don't remember the database name. You can just enter first into Psql by running: sudo -u postgres psql In some systems, sudo command is not available, you can instead run either command below: psql -U postgres psql --username=postgres 2. Show tables Now in Psql you could run commands such as: \? list all the commands \l list databases \conninfo display information about current connection \c [DBNAME] connect to new database, e.g., \c template1 \dt list tables of the public schema \dt .* list tables of certain schema, e.g., \dt public.* \dt *.* list tables of all schemas Then you can run SQL statements, e.g., SELECT * FROM my_table; (Note: a statement must be terminated with semicolon ; ) \q quit psql

评论作者信息不可用291 votes

Login as superuser: sudo -u postgres psql You can list all databases and users by \l command, (list other commands by \? ). Now if you want to see other databases you can change user/database by \c command like \c template1 , \c postgres postgres and use \d , \dt or \dS to see tables/views/etc.

评论作者信息不可用229 votes
源数据· Raw Archive
source
Stack Overflow
upstream_source
stackoverflow
upstream_item_id
769683
daily_ranking_item_id
2326867a-04f8-496a-b256-6446be910b62
rank_date
2026-06-01
rank
8
name
How to show tables in PostgreSQL?
tagline
database, postgresql, command, database-table, dbtable
description
What's the equivalent to show tables (from MySQL) in PostgreSQL?
votes_count
2,647
comments_count
28
created_at_on_source
2009-04-20T19:07:39.000Z
topics
databasepostgresqlcommanddatabase-tabledbtable
media / source-specific data
{
  "stackoverflow": {
    "score": 2647,
    "view_count": 3407024,
    "is_answered": true,
    "top_answers": [
      {
        "body": "From the psql command line interface, First, choose your database \\c database_name Then, this shows all tables in the current schema: \\dt Programmatically (or from the psql interface too, of course): SELECT * FROM pg_catalog.pg_tables; The system tables live in the pg_catalog database.",
        "score": 3769,
        "answer_id": 769706,
        "is_accepted": true
      },
      {
        "body": "You can use PostgreSQL's interactive terminal Psql to show tables in PostgreSQL. 1. Start Psql Usually you can run the following command to enter into psql: psql DBNAME USERNAME For example, psql template1 postgres One situation you might have is: suppose you login as root, and you don't remember the database name. You can just enter first into Psql by running: sudo -u postgres psql In some systems, sudo command is not available, you can instead run either command below: psql -U postgres psql --username=postgres 2. Show tables Now in Psql you could run commands such as: \\? list all the commands \\l list databases \\conninfo display information about current connection \\c [DBNAME] connect to new database, e.g., \\c template1 \\dt list tables of the public schema \\dt <schema-name>.* list tables of certain schema, e.g., \\dt public.* \\dt *.* list tables of all schemas Then you can run SQL statements, e.g., SELECT * FROM my_table; (Note: a statement must be terminated with semicolon ; ) \\q quit psql",
        "score": 291,
        "answer_id": 47185648,
        "is_accepted": false
      },
      {
        "body": "Login as superuser: sudo -u postgres psql You can list all databases and users by \\l command, (list other commands by \\? ). Now if you want to see other databases you can change user/database by \\c command like \\c template1 , \\c postgres postgres and use \\d , \\dt or \\dS to see tables/views/etc.",
        "score": 229,
        "answer_id": 9309377,
        "is_accepted": false
      }
    ],
    "answer_count": 28,
    "accepted_answer_id": 769706,
    "last_activity_date": 1738936692
  }
}
raw_payload
{
  "stats": {
    "score": 2647,
    "view_count": 3407024,
    "is_answered": true,
    "answer_count": 28,
    "creation_date": 1240254459,
    "last_edit_date": 1695503214,
    "accepted_answer_id": 769706,
    "last_activity_date": 1738936692
  },
  "api_wrapper": {
    "backoff": null,
    "has_more": true,
    "page_size": 8,
    "quota_max": 300,
    "quota_remaining": 248
  },
  "question_id": 769683,
  "answer_fetch": {
    "has_more": true,
    "answers_fetched": 3,
    "answer_page_size": 3
  },
  "snapshot_version": "stackoverflow_question_v1"
}
source_raw_snapshot
{
  "id": "5e0218fe-ead3-457f-b770-92b9e6628f4e",
  "daily_ranking_item_id": "2326867a-04f8-496a-b256-6446be910b62",
  "source": "stackoverflow",
  "external_id": "769683",
  "fetched_at": "2026-05-31T22:01:57.241Z",
  "question_raw": {
    "body": "<p>What's the equivalent to <code>show tables</code> (from MySQL) in PostgreSQL?</p>\n",
    "link": "https://stackoverflow.com/questions/769683/how-to-show-tables-in-postgresql",
    "tags": [
      "database",
      "postgresql",
      "command",
      "database-table",
      "dbtable"
    ],
    "owner": {
      "link": "https://stackoverflow.com/users/63051/flybywire",
      "user_id": 63051,
      "user_type": "registered",
      "account_id": 24717,
      "reputation": 277422,
      "accept_rate": 95,
      "display_name": "flybywire",
      "profile_image": "https://www.gravatar.com/avatar/b4b87a82355f286bb410cc1854389226?s=256&d=identicon&r=PG"
    },
    "score": 2647,
    "title": "How to show tables in PostgreSQL?",
    "view_count": 3407024,
    "is_answered": true,
    "question_id": 769683,
    "answer_count": 28,
    "creation_date": 1240254459,
    "last_edit_date": 1695503214,
    "protected_date": 1507437744,
    "content_license": "CC BY-SA 4.0",
    "accepted_answer_id": 769706,
    "last_activity_date": 1738936692
  },
  "answers_raw": [
    {
      "body": "<p>From the <code>psql</code> command line interface,</p>\n\n<p>First, choose your database</p>\n\n<pre><code>\\c database_name\n</code></pre>\n\n<p>Then, this shows all tables in the current schema:</p>\n\n<pre><code>\\dt\n</code></pre>\n\n<hr>\n\n<p>Programmatically (or from the <code>psql</code> interface too, of course):</p>\n\n<pre><code>SELECT * FROM pg_catalog.pg_tables;\n</code></pre>\n\n<p>The system tables live in the <code>pg_catalog</code> database.</p>\n",
      "owner": {
        "link": "https://stackoverflow.com/users/14444/mihai-limb%c4%83%c8%99an",
        "user_id": 14444,
        "user_type": "registered",
        "account_id": 8126,
        "reputation": 68904,
        "display_name": "Mihai Limbășan",
        "profile_image": "https://www.gravatar.com/avatar/b36b03508fc1473df72d9913e32d62dd?s=256&d=identicon&r=PG"
      },
      "score": 3769,
      "answer_id": 769706,
      "is_accepted": true,
      "question_id": 769683,
      "creation_date": 1240254777,
      "last_edit_date": 1564551307,
      "content_license": "CC BY-SA 4.0",
      "last_activity_date": 1564551307
    },
    {
      "body": "<p>You can use PostgreSQL's interactive terminal Psql to show tables in PostgreSQL.</p>\n<p><strong>1. Start Psql</strong></p>\n<p>Usually you can run the following command to enter into psql:</p>\n<pre><code>psql DBNAME USERNAME\n</code></pre>\n<p>For example, <code>psql template1 postgres</code></p>\n<p>One situation you might have is: suppose you login as root, and you don't remember the database name. You can just enter first into Psql by running:</p>\n<pre><code>sudo -u postgres psql\n</code></pre>\n<p>In some systems, sudo command is not available, you can instead run either command below:</p>\n<pre><code>psql -U postgres\npsql --username=postgres\n</code></pre>\n<p><strong>2. Show tables</strong></p>\n<p>Now in Psql you could run commands such as:</p>\n<ol>\n<li><code>\\?</code> list all the commands</li>\n<li><code>\\l</code> list databases</li>\n<li><code>\\conninfo</code> display information about current connection</li>\n<li><code>\\c [DBNAME]</code> connect to new database, e.g., <code>\\c template1</code></li>\n<li><code>\\dt</code> list tables of the public schema</li>\n<li><code>\\dt &lt;schema-name&gt;.*</code> list tables of certain schema, e.g., <code>\\dt public.*</code></li>\n<li><code>\\dt *.*</code> list tables of all schemas</li>\n<li>Then you can run SQL statements, e.g., <code>SELECT * FROM my_table;</code>(Note: a statement must be terminated with semicolon <code>;</code>)</li>\n<li><code>\\q</code> quit psql</li>\n</ol>\n",
      "owner": {
        "link": "https://stackoverflow.com/users/2700356/yuci",
        "user_id": 2700356,
        "user_type": "registered",
        "account_id": 3197479,
        "reputation": 30827,
        "accept_rate": 76,
        "display_name": "Yuci",
        "profile_image": "https://www.gravatar.com/avatar/3dfefc6b61d98e4285d12ad300567d23?s=256&d=identicon&r=PG"
      },
      "score": 291,
      "answer_id": 47185648,
      "is_accepted": false,
      "question_id": 769683,
      "creation_date": 1510160834,
      "last_edit_date": 1688675296,
      "content_license": "CC BY-SA 4.0",
      "last_activity_date": 1688675296
    },
    {
      "body": "<p>Login as superuser:</p>\n\n<pre><code>sudo -u postgres psql\n</code></pre>\n\n<p>You can list all databases and users by <code>\\l</code> command, (list other commands by <code>\\?</code>).</p>\n\n<p>Now if you want to see other databases you can change user/database by <code>\\c</code> command like <code>\\c template1</code>, <code>\\c postgres postgres</code> and use <code>\\d</code>, <code>\\dt</code> or <code>\\dS</code> to see tables/views/etc.</p>\n",
      "owner": {
        "link": "https://stackoverflow.com/users/74167/jlarky",
        "user_id": 74167,
        "user_type": "registered",
        "account_id": 27932,
        "reputation": 10321,
        "accept_rate": 0,
        "display_name": "JLarky",
        "profile_image": "https://www.gravatar.com/avatar/042954598c983c28f0aa2cb6dc5a0fda?s=256&d=identicon&r=PG"
      },
      "score": 229,
      "answer_id": 9309377,
      "is_accepted": false,
      "question_id": 769683,
      "creation_date": 1329387200,
      "content_license": "CC BY-SA 3.0",
      "last_activity_date": 1329387200
    }
  ],
  "tags_raw": [
    "database",
    "postgresql",
    "command",
    "database-table",
    "dbtable"
  ],
  "stats_raw": {
    "score": 2647,
    "view_count": 3407024,
    "is_answered": true,
    "answer_count": 28,
    "creation_date": 1240254459,
    "last_edit_date": 1695503214,
    "accepted_answer_id": 769706,
    "last_activity_date": 1738936692
  },
  "selection_meta": {
    "site": "stackoverflow",
    "api_wrapper": {
      "backoff": null,
      "has_more": true,
      "page_size": 8,
      "quota_max": 300,
      "quota_remaining": 248
    },
    "answer_fetch": {
      "backoff": null,
      "has_more": true,
      "answers_fetched": 3,
      "quota_remaining": 214,
      "answer_page_size": 3
    },
    "snapshot_version": "stackoverflow_question_v1",
    "selection_strategy": "tag_whitelist_unanswered_high_score_recent_active"
  },
  "created_at": "2026-05-31T22:01:57.473Z",
  "updated_at": "2026-05-31T22:01:57.473Z"
}