Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgreSQL error initdb: command not found

i was installing postgresql on ubuntu using linuxbrew:

brew install postgresql

it seems to work fine but after that because i was installing PostgreSQL for the first time i tried creating a database:

initdb /usr/local/var/postgres -E utf8

but it returned as:

initdb: command not found

i tried running the command with sudo but that doesn't helped

like image 200
Ahmed Reza Siddique Avatar asked May 22 '17 03:05

Ahmed Reza Siddique


People also ask

What is Initdb in postgresql?

initdb initializes the database cluster's default locale and character set encoding. The character set encoding, collation order ( LC_COLLATE ) and character set classes ( LC_CTYPE , e.g., upper, lower, digit) can be set separately for a database when it is created.

How do I run Initdb on Linux?

To initialize in such a setup, create an empty data directory as root, then use chown to assign ownership of that directory to the database user account, then su to become the database user to run initdb.

Could not connect to server could not connect to server No such file or directory?

When connecting to Postgres you might see this error: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket <some socket> . This happens most often when Postgres' server daemon process is not running.


2 Answers

run locate initdb it should give you the list to chose. smth like:

MacBook-Air:~ vao$ locate initdb
/usr/local/Cellar/postgresql/9.5.3/bin/initdb
/usr/local/Cellar/postgresql/9.5.3/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.5.3/share/man/man1/initdb.1
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
/usr/local/Cellar/postgresql/9.6.1/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.6.1/share/man/man1/initdb.1
/usr/local/bin/initdb
/usr/local/share/man/man1/initdb.1

So in my case I want to run

/usr/local/Cellar/postgresql/9.6.1/bin/initdb 

If you don't have mlocate installed, either install it or use

sudo find / -name initdb
like image 183
Vao Tsun Avatar answered Sep 19 '22 08:09

Vao Tsun


There's a good answer to a similar question on SuperUser.

In short:

  1. Postgres groups databases into "clusters", each of which is a named collection of databases sharing a configuration and data location, and running on a single server instance with its own TCP port.
  2. If you only want a single instance of Postgres, the installation includes a cluster named "main", so you don't need to run initdb to create one.
  3. If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command pg_createcluster to be used instead of initdb, with the latter not included in PATH so as to discourage end users from using it directly.

And if you're just trying to create a database, not a database cluster, use the createdb command instead.

like image 33
David Scarlett Avatar answered Sep 21 '22 08:09

David Scarlett