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?
asked Nov 5, 2013 at 21:20
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.
answered Nov 6, 2013 at 2:00
5
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
.
answered Jan 8, 2014 at 21:44
4
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.
answered Jul 14, 2018 at 4:32
ilias iliadisilias iliadis
3111 gold badge2 silver badges9 bronze badges
Follow the following steps with user root
passwd postgres
— your passwordsu postgres
psql
- Create a user with your user name like
CREATE USER SAM ;
create database sam;
- Log out and type
psql <your_user>
answered Jan 16, 2014 at 12:32
smn_onrockssmn_onrocks
5265 silver badges14 bronze badges
1
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
asked May 22, 2017 at 3:31
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
answered May 22, 2017 at 7:24
There’s a good answer to a similar question on SuperUser.
In short:
- 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.
- 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. - If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command
pg_createcluster
to be used instead ofinitdb
, with the latter not included inPATH
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.
answered Jul 18, 2017 at 1:33
David ScarlettDavid Scarlett
3,1512 gold badges11 silver badges28 bronze badges
I had the same problem and found the answer here.
Ubuntu path is
/usr/lib/postgresql/9.6/bin/initdb
Edit: Sorry, Ahmed asked about linuxbrew, I’m talking about Ubuntu.
I Hope this answer helps somebody.
answered Feb 1, 2018 at 4:10
I had a similar issue caused by the brew install postgresql
not properly linking postgres. The solve for me was to run:
brew link --overwrite postgresql
answered Aug 25, 2022 at 14:23
elkelkelkelk
1,6922 gold badges13 silver badges20 bronze badges
you can add the PATH to run from any location
sudo nano ~/.profile
inside nano go to the end and add the following
# set PATH so it includes user's private bin if it exists
if [ -d "/usr/lib/postgresql/14/bin/" ] ; then
PATH="/usr/lib/postgresql/14/bin/:$PATH"
fi
and configure the alternative
sudo update-alternatives --install /usr/bin/initdb initdb /usr/lib/postgresql/14/bin/initdb 1
answered Sep 11, 2022 at 13:52
I am reinstalling PostgreSQL using pgInstaller postgresql-8.3.16-1. An Error occurs in the last step of the install process:
Failed to run initdb:1!
tmpinitdb.log
shows this message:
The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event log or
use the command-line sxstrace.exe tool for more detail.
The message is quite simple but I can’t locate the root cause of the install failure.
Any one knows what’s the reason?
asked Oct 23, 2011 at 15:52
1
You probably already have a database cluster installed in the location where your Posgres8.3 install is trying to init a new one. You can’t really mix and match versions like that.
If possible, install the old version you had when you created the existing database. Then use pg_dumpall to create a .SQL
dump of all of your data. You can then move or delete the old database (usually at /var/lib/pgsql
) and install the new version. finally, apply the database dump to get the old data back.
For more details on this, read the Upgrading a PostgreSQL cluster manual page.
If you are installing the same version, there’s no need to upgrade the cluster, you can probably safely ignore errors about initdb
, so long as everything runs Ok.
answered Oct 23, 2011 at 16:01
Step 1: I installed PostgreSQL using sudo apt-get install postgresql-9.1
as recommended on the PostgreSQL website
Step 2: I tried to run postgres
. It’s not found. For whatever reason, the install doesn’t appear to add it to the path? So I had to manually add the line export PATH=$PATH:/usr/lib/postgresql/9.1/bin
to the bottom of my ~/.profile
. (Sidenote: Anybody know why this is necessary? Am I doing something wrong with the install? Everything else I’ve installed in Ubuntu «just works» without changing the $PATH
…)
Step 3: I try running initdb /usr/local/var/postgres
. Permission denied. I try running sudo initdb /usr/local/var/postgres
. Result is sudo: initdb: command not found
. How is this command not found? I just ran the damn thing! echo sudo $PATH
shows the PostgreSQL directory in the path… what am I missing?
I’m a bit of a newbie in Linux, but these are the sorts of super-irritating problems I keep running into!
UPDATE: I believe it’s related to this question. However, running the command with sudo -i
does not fix the problem. I just get: -bash: initdb: command not found
. Great.
UPDATE: This seems even closer. So I added alias sudo='sudo env PATH=$PATH'
to my .bashrc
as instructed. Still doesn’t effin’ work! It looks like the alias isn’t working. When I run alias
, I only show a single one. And yet my .bashrc
is full of them… so something is wrong with those getting set up.
UPDATE: Since I’m using Ubuntu and RVM, RVM recommended that I set up the terminal to «Run command as login shell». Based on reading I did here, it seems that the .bashrc
file isn’t read in a login shell, only profile. So I moved the alias
line from .bashrc
to .profile
, so .profile
now has this at the end:
export PATH="/usr/lib/postgresql/9.1/bin:$PATH"
alias sudo='sudo env PATH=$PATH'
… and it still doesn’t work. Running alias
only shows an RVM alias, but not the sudo
alias I tried to set up.
UPDATE From this site, I read about the precedence of dotfiles. It looks like .bash_profile
comes before .profile
. That being said, my PATH
additions were done in .profile
, and seemed to be loaded just fine, so why wasn’t the alias
also working? Moving the alias
into .bash_profile
from .profile
worked, however. Mystery. So then the alias
command shows my new alias. I finally type in sudo initdb /usr/local/var/postgres
, to be met with: initdb: cannot be run as root
. Oh, really? Then why were you giving me permission errors?! So now I think the problem is that I just have to chown
the folder, but still run initdb
as my user rather than root
.
UPDATE Running the command sudo chown myuser /usr/local/var/postgres/
, and then running initdb
afterward allowed the database to be initialized. Glad it was so obvious that the directory permissions needed to be set to myuser and not root. Incredible. Successful database init 4 hours later.
Run the «su — postgres -c …» command as root
I found the answer here: https://bugzilla.redhat.com/show_bug.cgi?id=771496
Description of problem: After initial install of a postgresql server
rpm, you are left with an unstartable service until you run the
following command as rootsu — postgres -c «initdb -D /var/lib/pgsql/data»
Version-Release number of selected component (if applicable):
[root@oscar]# rpm -q postgresql-server
postgresql-server-9.1.2-1.fc16.x86_64How reproducible: Always
Backstory
Several places had instructed me to use this command for Fedora 16, rather than following the prior instructions (new command: su — postgres -c «PGDATA=/var/lib/pgsql/data initdb» ), but upon seeing ‘su’ at the front of that, I assumed it would switch me to root when I ran the command. It kept prompting me for a password, but nothing was working.
I tried the root passwd, my own (as if sudo’ing), «postgres» and «pgsql» in case I was somehow supposed to be doing this as the postgres user, even leaving the password blank. I tried su’ing to root, and then running the command without the initial ‘su -‘ (starting with «postgres -c …»), but that errored as well, telling me that:
«The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for more
information on how to properly start the server.»
Finally, I tried running the full command «su — postgres -c …» as root, but still using the «su», and wow- it worked. Now the service starts. Thanks Redhat bug tracking!
Summary
su to root, then enter:
su — postgres -c «PGDATA=/var/lib/pgsql/data initdb»