在 OSX 上为 PostgreSQL 创建数据库和客户端连接

Creating a database and connection with client for PostgreSQL on OSX

如何启动 PostgreSQL 数据库并在终端中连接客户端?

我在用 brew 安装 postgreSQL 后试过这个。

which psql

结果:

/usr/local/bin/psql

然后我尝试启动数据库:

pg_ctl init -D /usr/local/bin/psql

给出:

The files belonging to this database system will be owned by user "matt".
This user must also own the server process.

The database cluster will be initialized with locale "en_AU.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

initdb: could not access directory "/usr/local/bin/psql": Not a directory
pg_ctl: database system initialization failed

来自 PostgreSQL pg_ctl 文档:

-D datadir

--pgdata datadir

Specifies the file system location of the database configuration files. If this is omitted, the environment variable PGDATA is used.

您正在将 pgsql 可执行文件指定为您的数据目录。

您必须先创建一个数据目录,并在-D后输入它的名字。假设您创建的数据目录是 /usr/local/bin/psql,那么您的初始化命令将是

pg_ctl init -D /usr/local/bin/psql/data