How to get Postgresql backup by command in Redhat6.9? - postgresql

I'm using postgresql9.2 and OS Redhat6.9; While getting backup from postgresql database backup from command line found a error.
I'm using two command like
[root#clipntouch ~]# pg_dump -h localhost -U adempiere -W -F t live_3001 > database_dump_file.tar
or
[root#clipntouch ~]# pg_dump -U adempiere live_3001 | gzip > /home/database_dump_file.gz
Find 2 error-
1. For first one- pg_dump: [archiver (db)] connection to database "live_3001" failed: FATAL: password authentication failed for user "adempiere"
2. For second one- psql.bin: FATAL: password authentication failed for user "root"
Any best solution ?

The errors are very clear and verbose,
Error 1 : After you hit enter, you had to provide the password for the DB User, the password you typed was incorrect.
Error 2 : You didn't specify the parameter [-W] so it didn't ask for any password. This would work if the postgres server configuration was set to TRUST for localhost but the default configuration is always set to md5 or peer.
To solve this, all you need to do is to understand pg_dump tool.
Example: pg_dump -Fc -h localhost -d adempiere -U adempiere -v -W > file.backup
Understanding Parameters
-h It corresponds to Host where the database is located
-d Refers to the database you try to backup
-U It referes to the database user with backup privileges
-W This parameters let you type the database user password after you run the command
-Fc It allows you to generate a custom format file .backup
-v Verbose, It let you see the log of what is happening in the background.
You can find more information about this command in the following link:
https://www.postgresql.org/docs/9.5/app-pgdump.html

Related

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

Postgres ERROR: permission denied for table

I have a dump file generated by using pg_dump from a remote database. I am using the file to restore and populate a database using psql.
I did not have the user and database name. I peeked into the sql file and figured out the user and database.
Here are my steps:
1. psql -h <> -u <> -d ( I used the superuser here).
2. created the user as the application needs to access using this user only.
3. changed the owner of the database to the user created in step 2 using Pgadmin.
I am unable to access any tables and getting the error -- ERROR: permission denied for table
Please Help !
Thanks
It is better if you use dump and restore instead of psql for restoring the database.
e.g
e.g suppose you have database dbname_source in remoteDB and dbname_target in localDB then you can use the below commands for dump and restore
./pg_dump -U postgres -p 5432 -h <remote_IP> -Ft dbname_source > dump_of_source.sql.tar
./pg_restore -U postgres -h localhost -p 5432 -d dbname_target dump_of_source.sql.tar

pg_dump: How to set username and password for the *.sql output file?

I want to create a local copy of an external postgres database. I am asked for the password of the local copy. Where can I set/access this password? I never set a password.
pg_dump -h external_hostname -p 5432 -U postgres db > db_copy.sql
createdb -p 5432 -h 127.0.0.1 -U postgres db_copy
I get the error
createdb: could not connect to database template1: FATAL: password authentication failed for user “postgres”
First you should find your pg_hba.conf file with
show hba_file;
Its place can be change but if you use debian based system, must be about etc/postgresql/9.6/main/pg_hba.conf
open this file and change
local all postgres peer
to
local all postgres trust
After all you should reload postgresql service from root, or easy way to reload is that, you run this select query by open psql :
select pg_reload_conf();

postgresql pg_dumpall password error

postgresql 9.4 following this cheat sheet http://www.postgresonline.com/special_feature.php?sf_name=postgresql90_pg_dumprestore_cheatsheet&outputformat=html trying to backup
here is my command
C:\Program Files\PostgreSQL\9.4\bin>pg_dumpall -h arcserver -U postgres -w -p 5433 -f "R:\Data\LUCZ_2017\PostgreSQL_Backup\lucz.sql"
then it gives me this strange error
pg_dumpall: could not connect to database "template1": fe_sendauth: no password supplied
what is template1? as you can see in the picture there is no template1?
I put in the -w so it doesnt ask me for the password..
what am I doing wrong here?
pg_dumpall will try to dump the entire cluster (all databases that the engine serves). If you need this functionality, you probably only want to dump your lucz database (I'm assuming). Try using the -d option to specify the database to dump.
For help:
pg_dumpall --help
or https://www.postgresql.org/docs/9.4/static/app-pg-dumpall.html

pg_dump fails with error: `FATAL: role "username" does not exist`

I have a db named backupdb, I want to import this to my local rails app so I want to take a dump of it.
When I am running pg_dump backupdb, I am getting below error.
pg_dump: [archiver (db)] connection to database "backupdb" failed: FATAL: role "username" does not exist
what's wrong here. Please help.
I downloaded the db from my email and then trying to create a dump so I can import it to my local rails app
Try this way, it works!!
$ pg_dump -h localhost -U postgres -Fc mydb > db.dump
This command will take the backup of complete database
pg_dump -h localhost -U "dbuser" "dbname" -Fc > "pathfilename.backup"
**ex:** pg_dump -h localhost -U mani manidb - Fc > "thamesdb.backup"
for more pg_dump formats please refer to this answer
You're giving "username" as username, which does not exist. You need to pass a username that exists (postgres would probably do).
add parameters --username=postgres --password and it will ask you for the password for user postgres. (you might have security set to trust in your pg_hba.conf in which case leaving out --password would work.
If someone has the same problem using intellij, here is what helped me:
In my case the Problem was, that i right clicked the datasource, but you have to open it and right click the database itself. So in the image below don't click on localDB. Right click the database name and then do a dump.
Hope this will help someone to solve this confusing UX problem. :D
I was having the same problem but after trying out different permutations of the command options while referencing the documentation, I was able to get it running with this order of options. The command I used is:
pg_dump.exe -h localhost -U postgres -t "shop*" -t "core*" -t "profiles*" -f "path/to/output/dir_or_file" mydbname
Where:
option prefix
option
params
-h
host
localhost
-U
username
postgres
-t
Tables
Any tables whose name starts with (shop, core, or profiles (NOTE: for django app tables in my case))
-f
file out
path where I want to save the dumped file
(End of cmd)
database
mydbname
Note: as I have multiple versions of postgresql on my computer, I had to call the newest pg_dump executable. (Just for reference)