postgresql dump on ubuntu for user postgres - postgresql

I'm logged into remote using ssh
ubuntu#ubuntu:~$
now I switch to postgres account using sudo su - postgres command and it send me to postgres#ubuntu:~$
now here I'm able to take dump using pg_dump command.
e.g. postgres#ubuntu:~$ pg_dump db_name > mydbdump.sql
so far looks good. but from here I want to copy this dump file to my local machine or even to my origin/default ubuntu user on remote(ubuntu#ubuntu:~$). so that from there I can scp.
how do I copy these dump sql files from postgres acccount to ubuntu on remote?

If you are using ubuntu, default directory would be /var/lib/postgresql
so you can directly scp from remote to local.
On your local machine run this command
user#user:~$ scp ubuntu#someaddress.com:/var/lib/postgresql/mydbdump.sql /path/to/local/dir

Related

Restore pg_dump with pgAdmin

i'm trying to restore a pg_dump with pgAdmin 4.
this is the command i've used to create the backup pg_dump -U {dbUser} -h localhost -Fc {dbName} > {backupFolder}/{backupName}, but when i try to restore it using pgAdmin i get this:
If i execute the command pg_restore manually i get this error
pg_restore: error: could not read from input file: end of file
I've created the dump on a linux machine and trying to restore it with pgAdmin from a windows machine to the linux machine
any help? thanks!
The problem was actually the ftp method i was using to transfer the dump... The file was a bit bigger after the ftp transfer, fixing the ftp transfer have solved the problem!

Want to execute a local sql file (using \i to execute multiple sql files) using psql command on ssh server

I have multiple .sql files on my local machine, which I was executing rapidly with one command
psql .....-f abc.sql (containing \i def.sql; \i ghi.sql) on db server hosted on aws.
Now, I have established SSH tunneling with this db server and want to execute my local sql files on this server to rapidly create, drop, update objects on db hosted on aws.
I have tried
1. cat abc.sql | ssh -i abc.pem user#server.com psql -c
simple : How to execute my local files on SSH server using psql command?
You don't need the -c at the end of the command. However, when the script encounters the \i command, it will try to load the files locally from the server. You will either have to send them there via scp, or include them completely inline to the master script.

How to restore PostgreSQL database backup without psql and pg_restore?

I am using postgresql on an embedded device running yocto (customized linux). The package containing postgresql does not provide psql or pg_restore. /usr/bin provides the following tools:
pg_basebackup indicates that I am able to create backups. But how am I supposed to restore a backup within a terminal? With pg_restore or psql this would not be a problem for me.
Please note: I want to use a backup created on my windows/linux computer to create the initial database on the embedded device.
Create backup of the db using command:
pg_basebackup -h {host_ip} -D pg_backup -U {USER}
for restoring just change the data folder to pg_backup. Now start the psql server.

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

PostgreSQL client -- How To Start It?

I just installed PostgreSQL-8.4 on Ubuntu. How do I start it / its GUI, connect to a database etc? I know SQL, but can't find PostgreSQL's icon in my Ubuntu 10.04 desktop (hence, am not sure how to start it).
Postgresql has no built in gui.
to check if it is running run the following from a terminal
ps aux | grep postgres
You can use psql to access from the command line.
to install psql
aptitude install postgresql-client
then to run
psql -h dbhost -U username dbname
If you want a gui intall package pgadmin
aptitude install pgadmin3
I start postgres prompt by using the following command:
sudo -u postgres psql
I use Ubuntu 14.04
If you're a Mac user, try running this
postgres -D /usr/local/var/postgres
then do
psql
you may start by firing up a graphical client. In a terminal type : pgadmin3
You will be presented with the pgAdmin III interface. Click on the "Add a connection to a server" button (top left). In the new dialog, enter the address 127.0.0.1, a description of the server, the default database ("mydb" in the example above), your username ("postgres") and your password.
With this GUI you may start creating and managing databases, query the database, execute SQl etc.
check out - https://help.ubuntu.com/community/PostgreSQL