问题
I'm a Windows user - it took me a couple of hours of constant installs and uninstalls before I could get this working, with the first 10 or so times coming to see the error message in the title.
I place this here as a self-answered question to prevent others who might run into the same problem while installing, and include some basic usage methods for those like me who are first comers in using PostgreSql.
回答1:
You have to mannualy run initdb which is present : "C:\Software\PostgreSql\12\bin"
Now make sure u associate "postgres" as user alongwith the initdb cmd since "postgres" is the superuser that got created during installation.
initdb -D "D:\PostgreSql\12\data" -U postgres
Now once database cluster is initialized then you can start the server by using pg_ctl utility present inside bin folder of PostgreSql\12
pg_ctl start -D "D:\PostgreSql\12\data"
Or you can also register it as a windows service and you can set it to automatic
pg_ctl register -N PostgreSql-12.3.1 -D "D:\PostgreSql\12\data"
Now you are all set to use the postgresql database. Either use it through cmd line (psql) or pgAdmin4
回答2:
Installation)
Download the appropriate install file for your system.
Make sure to install to the default path:
C:\Program Files (x86)\PostgreSQL\9.3\ was the default on my system.
Not installing to the default path may give you dll errors and whatnot.
If installation completed with no problem,
PostgreSql would have created a database with the user postgres and the password being the value you inputted during installation.
- Add the
PostgreSQL\9.3\binfolder to your PATH.
PostgreSql usage)
What's important in now using PostgreSql is this:
login is as user postgres for whatever command you want to use.
Ignoring this will give you constant password authentication failed messages, since you'll be attempting to login as your PC's ID.
For example)
- logging into psql)
psql -U postgres
- creating a new database)
createdb -U postgres [dbname] [etc...]
- executing a sql data file (ex. data.sql) within a certain database)
psql -U postgres -f data.sql dbname
Additional Usage
Once logged into psql (through psql -U postgres), you can use the following commands
\llist the available databases\c [dbname]'connect' to a database\ddisplay the description of that database (once connected)
I hope this helps.
I'll add some more examples if I run into any more problems during my first couple of days of usage.
回答3:
I faced some major issues with this myself when trying to install PostgreSQL 9.6 and couldn't get it working despite the above answers. What solved it for me was either
In the installer
When prompted for locale, do not check 'default locale'. Instead, choose something like 'United States English'. For some reason, the default doesn't work.
After the installer
If you went ahead and checked 'default locale' anyways, you can still fix the installation errors without reinstalling the whole thing. What you need to do is similar to above answers, but with slight changes:
- Go to your postgres /bin directory (default location:
"C:\Program Files\PostgreSQL\9.6\bin") and execute the following query:
initdb -D "C:\Program Files\PostgreSQL\9.6\data" -U postgres --locale="English_United States.1252"
As you can see, locale is not an intuitive string such as "en_US.UTF8", so this can get quite nasty if you don't know what is going on. Anyways, the above code should result in a "Success" message.
- Next, execute the following command:
pg_ctl register -N PostgreSQL -D "C:\Program Files\PostgreSQL\9.6\data"
This should result in a windows service called PostgreSQL.
- Lastly, to start your newly created service, enter:
net start PostgreSQL
That's it. everything should be up and running now.
来源:https://stackoverflow.com/questions/23533980/postgresql-running-post-install-step-the-database-cluster-initialisation-failed