15

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?

14

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.

  • 4
    Quoting from /usr/share/doc/postgresql-common/README.Debian.gz: Please note that you can of course also use the upstream tools for creating clusters, such as initdb(1). However, please note that in this case you cannot expect *any* of above pg_* tools to work, since they use different configuration settings and file locations. If in doubt, then do *not* use initdb, but only pg_createcluster. Since merely installing postgresql-X.Y will already set up a default cluster which is ready to work, most people do not need to bother about initdb or pg_createcluster at all. – cdaddr May 14 '14 at 7:56
  • 3
    Even after switching to the postgres user I still get this error – Cogwheel May 13 '17 at 19:04
  • This doesn't work for me in Ubuntu Server 14 using Postgres 9.6. – sudo Jul 7 '17 at 22:17
  • It does not work, since initdb is in /usr/lib/postgresql/X.X/bin/. – Li Dong Nov 15 '17 at 9:07
27

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.

  • This really should be the accepted answer. initdb is the underlying command but Debian and Ubuntu users should be using pg_createcluster and its related suite of commands. Furthermore you normally do not need to initdb OR pg_createcluster after apt-get install postgresql because the standard install already creates a default cluster, with a server and default/template databases, for you. The README Peter mentions above is worth your time to read. – cdaddr May 14 '14 at 7:52
  • 2
    @cdaddr No, you usually don't need it after installing postgres. Still, if you find yourself in need of recreating a cluster quickly and don't want to bother with reinstalling postgres or if you need to initialise a new database in a non-standard location this may come in handy. So yes, this is a great answer. – Erathiel Nov 9 '15 at 10:12
  • 1
    Works. And it's the best because this way I can be sure which version I'm using. – sudo Jul 7 '17 at 22:17
  • we are searching for initdb because, tutorial says so postgresql.org/docs/10/static/creating-cluster.html – nerkn Dec 8 '17 at 8:05
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.

-2

foll the following steps from root 1.passwd postgres your password then 2.su postgres 3.psql 4. create user of your user name like "CREATE USER SAM ;" 5.create database sam; now log out 6.type psql to your user

  • This answer does not address the question directly at all. – cdaddr May 14 '14 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.