24

I'm following these instructions, however I can only get to step 17.2.

Despite installing postgresql successfully via the

sudo apt-get install postgresql

command, upon running

initdb -D /usr/local/pgsql/data

Ubuntu tells me that it 'initdb' isn't installed. The instructions tell me this command is installed by

sudo apt-get install postgresql

so what's going on? I can make initdb available by installing postgres-xc, but I think postgres-xc is just some weird third party rubbish, and it's not detailed in the instructions. Any ideas?

Starkers
  • 3,149

5 Answers5

34

You will find initdb under /usr/lib/postgresql/x.y/bin/. See also /usr/share/doc/postgresql-common/README.Debian.gz for more information on the setup on Debian and Ubuntu.

16

initdb is intended to be run under the postgres user account that is created during the install. After installing postgresql you can do:

sudo su - postgres

Then you should be able to run initdb.

Brian.D.Myers
  • 620
  • 9
  • 16
2

initdb is not installed as user executable. Is only installed in /usr/lib/postgresql/X.X/bin/, because it always depends on the version. initdb can only be executed from that specific directory.

As mentioned in other answers, installation of postgres creates a default directory that may be in a limited partition. Users may want to change this, but it requires other steps also. see here.

0

if you install postgresql and got initdb: command not found

you should add below line in ~/.bashrc (OR .zshrc) file:

export PATH=$PATH:/usr/lib/postgresql/x.y/bin/

and then

source ~/.bashrc

Actually the initdb is exist in that path. after that you can use initdb command.

AliHZ
  • 1
-2

Follow the following steps with user root

  1. passwd postgres - your password
  2. su postgres
  3. psql
  4. Create a user with your user name like CREATE USER SAM ;
  5. create database sam;
  6. Log out and type psql <your_user>
EAmez
  • 103