How to install progresql-9.3 properly - postgresql

I followed the installation on this document http://www.postgresql.org/download/linux/ubuntu/ and every thing seems to be fine. But when I try to this follow this tutorial: http://www.postgresql.org/docs/9.3/static/tutorial-createdb.html, everything is not fine any more. This is the error I got when I try to create a database table:
$ createdb mydb
WARNING: password file "/home/.../.pgpass" has group or world access; permissions should be u=rw (0600) or less
WARNING: password file "/home/.../.pgpass" has group or world access; permissions should be u=rw (0600) or less
createdb: could not connect to database template1: FATAL: role "..." does not exist
$ /usr/local/pgsql/bin/createdb mydb
bash: /usr/local/pgsql/bin/createdb: No such file or directory

You got one warning and one error.
You can handle the warning by this command of line in your terminal:
$ chmod 600 ~/.pgpass
When you write "psql" in your terminal, Postgres DBMS try to connect to the one database with your computer name but it can't find it. In other hand Postgrest create a database named "postgres" when it install so try connect to this and create your database. You can connect to "postgres" database easily with this command:
$ psql postgres
If you get the "connections on Unix domain socket "/tmp/.s.PGSQL.5432"?" error start your database with this command:
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Check the result with this command:
$ pg_ctl -D /usr/local/var/postgres status

The error message tells you what's wrong. Change the permissions on .pgpass:
chmod u=rw $HOME/.pgpass
Also, unless you edited the error message and didn't say so, you appear to actually be attempting to connect as user .... I imagine the examples you read said something like:
psql -U "..." template1
and assumed you'd replace "..." with the actual username.

Related

pg_restore connection to database failed error while restoring backup

I have a backup file in tar format and there is no problem while getting this backup. However, when trying to restore this backup using the following script, I encountered "pg_restore: error: connection to database "db-dev" failed: FATAL: password authentication failed for user "db-dev-user"" error after entering password.
pg_restore -v -h 127.0.0.1 -p 5432 -d db-dev -U db-dev-user < C:\dB\db-dev.tar
I am trying to restore this backup to a Docker container where I can easily create an empty database with the same name (db-dev). I am also using Windows 10. So, how can I fix the problem? May the problem related to Docker?
The -U option must specify an existing user in the target database, and you have to specify the user's password when calling pg_restore.
Use a user with the permissions required to create the dumped objects and make sure that the target's pg_hba.conf allows the user database access from your client machine.

Unable to execute postgres command

I'm having difficulty changing the password associated with the postgres user after installing postgres on my windows 10 machine. My apologies in advance as I'm quite unfamiliar with postgres as well as the commands required to work with it.
I've referenced the approved answer in the below article:
FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4)
I'm stuck on the step that requires me to
Connect using psql or pgAdmin4 or whatever you prefer
Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'
I don't quite understand this step. I've taken the following steps
Open cmd
run psql
The system then asks me for password for username jason. Regardless of what I enter, i get the following message:
psql: error: could not connect to server: FATAL: password authentication failed for user "jason"
At no point do I have an opportunity to enter the following command:
ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'
How can I run this command without being asked to enter a password for postgres?
Thanks!
The steps below require that you remember what you did when you installed PostgreSQL.
Locate the data directory where the installation process created the database cluster. By default, that would be a subdirectory of where you installed the software (which is a bad place)
Edit the pg_hba.conf file therein and add this line on top:
host postgres postgres 127.0.0.1/32 trust
Reload or restart PostgreSQL.
Start cmd.exe and enter
psql -h 127.0.0.1 -p 5432 -d postgres -U postgres
If psql is not on your PATH, use the absolute path C:\...\psql.
Use \password to change the password.

How to successfully restore a backup using pg_dump in postgresql?

I am new to Postrgresql. I want to create a backup of a production database and restore it in my development instance. Before I touch production, however, I want to make and restore a backup in development. I figured this would be a trivial effort, but that has not been the case.
I connected to psql using the command below.
sudo -u postgres psql
I ran the following command to create my backup inside psql.
\ pg_dump -U postgres -d dbname > /tmp/kp.bak
I included the "!" with the ""of the command above, but Stackoverflow is having trouble rendering that combination of characters
After that it prompted for a password. When I give it the correct password I get the following error. I reset the password for the PostgreSQL user using the ALTER PASSWORD command, so I know I have the correct password.
FATAL: password authentication failed for user "postgresql"
Since that doesn't work, I configured the pg_hba.conf to not require one and restarted the service. This has had no effect, as I am still prompted for a password when I try to restore. This is the first uncommented line in pg_hba.conf.
local all all trust
Here is the command I am using to do the restore.
\ pg_dump -U postgresql -h localhost -f \tmp\kp.bak dbname;
I am at a loss at how to move forward with this. Can anyone tell me what I am missing?
Thanks
Starting psql just to shell out to pg_dump doesn't make any sense. Just do it directly:
sudo -u postgres pg_dump ....
But once you have moved away from "peer" as your authentication method, there is no point in using the sudo at all, so just do it even more directly:
pg_dump ....
FATAL: password authentication failed for user "postgresql"
I don't find it believable that you specified -U postgres, yet the error message says user "postgresql". Please double check your post for spelling and typing errors.
I eventually got it to work with the following commands
sudo -U postgres psql
Then
\! pg_dump -U postgres -d dbname > /tmp/dbname.bak
Doing this outside of psql did not work. I received the following error despite running with sudo.
bash: /tmp/dbname.bak: Permission denied

Postgresql - postgres#localhost failed FATAL: role does not exist

I just installed postgres (with brew) and started it with pg_ctl -D /usr/local/var/postgres -l logfile start
I now try to connect to it in the terminal but get the following:
Connection to PostgreSQL - postgres#localhost failed
FATAL: role "me" does not exist
The issue might be that I first installed postgres.app and then didn't get it work right and then removed it.
You don't show what you typed and as which user you did it, but from the error message I'd say that you should add -U postgres to the psql invocation.

starting postgresql and pgadmin in windows without installation

How can I start PostgreSQL and pgAdmin III in windows without installation. I do not have admin rights in a system. so I need to start the application without installing . How can I do that?
Download the ZIP file from https://www.enterprisedb.com/download-postgresql-binaries
Unzip the archive into a directory of your choice (the archive is created such that unzipping it, it will create a directory pgsql with everything else below that)
Run initdb (this can be found in the subdirectory pgsql\bin)
initdb -D c:\Users\Arthur\pgdata -U postgres -W -E UTF8 -A scram-sha-256
This will create the postgres "data directory" (aka the "cluster") in c:\Users\Arthur\pgdata. You need to make sure that the user running this command has full read/write privileges on that directory.
-U postgres creates the superuser as postgres, -W will prompt you for the password of the superuser, -E UTF8 will create the database with UTF-8 encoding and -A scram-sha-256 enables the password authentication.
To start Postgres, run:
pg_ctl -D c:\Users\Arthur\pgdata -l logfile start
this has(!) to be done as the user who ran initdb to avoid any problems with the access to the data directory.
To shutdown Postgres, run:
pg_ctl -D c:\Users\Arthur\pgdata stop
psql.exe (the command line client) is located in the bin directory. Starting with Postgres 9.6 the pgAdmin executable pgAdmin4.exe is located in the sub-directory "pgAdmin 4\bin".
Optionally create a Windows service to automatically run Postgres (must be run using a Windows administrator account)
pg_ctl register -N postgresql -D c:\Users\Arthur\pgdata
Thank you. This worked for me. But, i was getting error while starting psql.exe
The error was "psql: FATAL : role [user] does not exist."
To resolve this, i followed the below steps:
Be on the same folder path (where you have initdb.exe) i.e. source-folder/pgsql/bin
Run "psql -U postgres". This will ask for password.
Now enter the password that was set during postgres intialization. This will open the psql command prompt.
Hope this helps.. :)
I tried above method its working fine, but when i tried to connect it via JDBC i used to get
"The authentication type 10 is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or
subnet, and that it is using an authentication scheme supported by the
driver."
This happens because scram-sha-256 has some issue(refer here), i couldn't understand in depth, so i changed it to md5, All started to work smoothly.hope it helps
.\initdb -D D:\database\dbdata -U postgres -W -E UTF8 -A md5