简体   繁体   English

在OSX上为PostgreSQL创建数据库并与客户端建立连接

[英]Creating a database and connection with client for PostgreSQL on OSX

How can I start a PostgreSQL database and connect with a client in terminal? 如何启动PostgreSQL数据库并与终端中的客户端连接?

I've tried this after installing postgreSQL with brew. 我在用brew安装postgreSQL之后尝试了这个。

which psql

Results in this: 结果:

/usr/local/bin/psql

Then I try to start database with: 然后,我尝试使用以下命令启动数据库:

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

Which gives: 这使:

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

You must create a data directory first and input its name after -D. 您必须先创建一个数据目录,然后在-D之后输入其名称。 Say if the data directory you created is /usr/local/bin/psql, then your init command will be 假设您创建的数据目录是/ usr / local / bin / psql,那么您的init命令将是

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

From the PostgreSQL pg_ctl documentation: 从PostgreSQL pg_ctl文档中:

-D datadir -D数据目录

--pgdata datadir --pgdata数据目录

Specifies the file system location of the database configuration files. 指定数据库配置文件的文件系统位置。 If this is omitted, the environment variable PGDATA is used. 如果省略,则使用环境变量PGDATA。

You are specifying your pgsql executable as your data directory. 您正在将pgsql可执行文件指定为数据目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM