# Discourse 如何通过终端工具访问 PGSQL

**URL:** <https://www.isharkfly.com/t/discourse-pgsql/16030>\
**Category:** Discourse\
**Tags:** discourse, postgresql\
**Created:** [July 25, 2024, 12:49pm UTC](https://www.isharkfly.com/t/discourse-pgsql/16030 "2024-07-25T12:49:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [July 25, 2024, 12:49pm UTC](https://www.isharkfly.com/t/discourse-pgsql/16030/1 "2024-07-25T12:49:25Z")

</div>

PGSQL 在 Discourse 中是通过容器方式运行的，要访问 PGSQL 中的数据那么首先需要进入到容器后才可以。

进入容器的命令为：

```auto
 cd /var/discourse/
 ./launcher enter app
 su discourse
 psql discourse

```

最后的命令是登录到运行在容器中的 pgsql。

查看 pgsql 上运行的数据库的命令为： `\l`

下面显示的是当前容器中运行的 pgsql 数据库。

```auto
discourse=> \l
                                                        List of databases
   Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges    
-----------+----------+----------+-----------------+-------------+-------------+------------+-----------+------------------------
 discourse | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =Tc/postgres +
           | | | | | | | | postgres=CTc/postgres +
           | | | | | | | | discourse=CTc/postgres
 postgres | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | 
 template0 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
           | | | | | | | | postgres=CTc/postgres
 template1 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
           | | | | | | | | postgres=CTc/postgres
(4 rows)

discourse=> ^C
discourse=> 

```

 ![2024-07-25_08-48-45](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/b/b96bb03b5003973b06554130df84c9f82738dbf0.png)

这也是直接访问 Discourse 数据库的方法，你可以在上面的命令行工具中执行 SQL。
