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.
痛点为 AI 基于上游原始证据的初步提炼;未包含额外中国市场检索。
用户从 MySQL 迁移到 PostgreSQL 后,需要快速了解数据库结构,但发现熟悉的 'show tables' 命令在 PostgreSQL 中无效。现有流程中,用户必须学习新的 psql 元命令(如 \dt)或查询系统表(如 pg_catalog.pg_tables),这增加了学习成本和操作步骤。对于不熟悉 PostgreSQL 命令行的开发者,这种语法差异导致频繁查阅文档或搜索,中断工作流,造成时间浪费和挫败感。
Stack Overflow question
What's the equivalent to show tables (from MySQL) in PostgreSQL?
Question details
- View count
- 3,406,997
- Answer count
- 28
- Last activity
- 2025/02/07
Answers
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
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.
源数据· Raw Archive
- source
- Stack Overflow
- upstream_source
- stackoverflow
- upstream_item_id
- 769683
- daily_ranking_item_id
- 7f29ee15-538a-4279-a72d-7738cf67a811
- rank_date
- 2026-05-31
- 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
{
"stackoverflow": {
"score": 2647,
"view_count": 3406997,
"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
}
}{
"stats": {
"score": 2647,
"view_count": 3406997,
"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": 210
},
"question_id": 769683,
"answer_fetch": {
"has_more": true,
"answers_fetched": 3,
"answer_page_size": 3
},
"snapshot_version": "stackoverflow_question_v1"
}{
"id": "239bacb3-8ed3-4d2f-a64e-8191db27ef18",
"daily_ranking_item_id": "7f29ee15-538a-4279-a72d-7738cf67a811",
"source": "stackoverflow",
"external_id": "769683",
"fetched_at": "2026-05-30T22:02:04.421Z",
"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": 3406997,
"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": 68894,
"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 <schema-name>.*</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": 3406997,
"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": 210
},
"answer_fetch": {
"backoff": null,
"has_more": true,
"answers_fetched": 3,
"quota_remaining": 177,
"answer_page_size": 3
},
"snapshot_version": "stackoverflow_question_v1",
"selection_strategy": "tag_whitelist_unanswered_high_score_recent_active"
},
"created_at": "2026-05-30T22:02:04.667Z",
"updated_at": "2026-05-30T22:02:04.667Z"
}