0

How can I start a PostgreSQL database and connect with a client in terminal?

I've tried this after installing postgreSQL with brew.

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

2 Answers 2

1

You must create a data directory first and input its name after -D. Say if the data directory you created is /usr/local/bin/psql, then your init command will be

pg_ctl init -D /usr/local/bin/psql/data
Sign up to request clarification or add additional context in comments.

Comments

0

From the PostgreSQL pg_ctl documentation:

-D datadir

--pgdata datadir

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

You are specifying your pgsql executable as your data directory.

1 Comment

Thanks, though I'm looking for the complete set of steps needed to start and use a database through the client ie how to find the directories and which commands

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.