Unable to restore complete database from pg_dump - postgresql-10

I ran the following command to backup my PostgreSQL database:
pg_dump -U postgres -h localhost -W -F t crewdb > /home/chris1/Documents/crewcut/crewdb/crewdb_bak.tar
This file was later saved to a USB.
After installing PostgreSQL on a new Ubuntu 18.04 system I ran the following command to restore the database from the USB:
psql -U postgres -d crewdb < /media/chh1/1818-305D/crewdb_bak.tar
The structure of the database has been recovered, so tables, views etc. except the actual data in the tables which has not been recovered.
Has anyone got an idea why this is and how to solve this.

I do not know if the command you ran to restore your data is correct; on any case try to use the pq_restore as says from the official documentation "restore a PostgreSQL database from an archive file created by pg_dump" that's the correct way to do it.
In my case I use pg_dumpall -U user > backup.sql then "cat backup.sql | psql -U user database"
I recommend you to check out the flags you're using on your pg_dump

Related

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "myname" does not exist

I a rails app running on my local environment using postgresql. This morning I spun up a new one and after install the pg gem, etc. I am running into the following error when trying to run
psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "jackcollins" does not exist
What's strange is the db name "jackcollins" is from my other rails app.
I ran
pgrep -l postgres
and the output was
20902 postgres
20919 postgres
20920 postgres
20921 postgres
20922 postgres
20923 postgres
20924 postgres
I'm unsure how to proceed so that these apps can both run their own postgres instance.
I had the same problem as you, after making attempts to reinstall, rm -rf xxx.pid, etc., I ended up executing the following command and was eventually able to connect to the PostgreSQL database.
brew install postgresql
an error message appears
run createdb (because macs don't create username databases after installing PostgreSQL)
execute psql to connect successfully.
Regarding the error, you are trying to connect to jackcollins, please can you test trying to connect using the database flag?:
psql -d your_database_name
If you type
psql --help
in the terminal, you will see that the default database is your username. Unless you have that database in PostgreSQL, you will get an error. Instead, you can run the command
psql -d your_database_name
Also, if you want to log in as a specific user (by default it is a current user):
psql -d your_database_name -U your_username -W
The last -W is for password. Hope, it helps!
In the absence of -d <database_name> psql will use the OS user name as the database name. As in many things it better to be explicit rather then implicit, especially when working on a new instance. In addition use -h <host_name>, -p <port_number> and -U <user_name>. Then you know who you are connecting as, as well as how. It is spelled out here psql and since psql is a libpq program in more detail here Key words.

Magento, database dump

I am trying to get db dump by command
docker exec container-name sh -c 'exec mysqldump --all-databases -uroot -p""' > db-backups/some-dump-name.sql
and I am getting
Got error: 2002: "Can't connect to local MySQL server through socket '/opt/bitn
ami/mysql/tmp/mysql.sock' (2)" when trying to connect
Magento runs on this image. Any ideas what could be wrong? I can provide more details if needed.
Bitnami Engineer here,
You also need to set the hostname of the database when backing up the databases. The Magento container doesn't include a database server, it uses an external one.
You probably specified that using the MARIADB_HOST env variable. If you used the docker-compose.yml file we provide, that hostname is mariadb.
exec mysqldump --all-databases -uroot -h HOSTNAME -p""

How to specify which database (not "master") in tsql (FreeDTS command line tool)

I am actually trying to connect to an MS SQL Server on Azure, from Python, via the module pymssql which relies on FreeTDS. I just can't make it work. I found the command line tool tsql which is supposedly for testing FreeTDS connections. And also, I can't connect with tsql. Regarding this, I have one very specific question.
How do I specify which "database" in the tsql tool. Fx if I use dbeaver, I must specify the database, "ava-iot". Using man tsql does not tell me how to specify another database.
When I try:
$ tsql -H uepbua32ii.database.windows.net -p 1433 -U Azure_SQL_Reader_Temporary -P XXXXXX
I get:
"The server principal "Azure_SQL_Reader_Temporary" is not able to access the database "master" under the current security context."
This tells me, that it is specifically trying to connect to a database named master. So how do I tell it to try the database ava-iot.
The reason this is happening is because your user Azure_SQL_Reader_Temporary has the default database set to be master. You can change that as well. But to answer your question of how to do it with tsql using the -D parameter.
tsql -H uepbua32ii.database.windows.net -p 1433 -D dbname -U Azure_SQL_Reader_Temporary -P XXXXXX
Good luck!

heroku postgres dump - not working locally

I have done this:
heroku pgbackups:capture
heroku pgbackups:url
downloaded file from url obtained from above result
Created psql db "abc"
Ran this comamnd locally:
pg_restore --verbose --clean -no-acl --no-owner -U uname -d abc ~/Downloads/b001.dump
output:
pg_restore: connecting to database for restore
pg_restore: implied data-only restore
I have loaded in 2ways. First created db, and directly ran pg_restore command. Then no tables created.
Then, thinking that dump contains only data, I have run migrations(means create table structure) on the new created db and ran pg_restore command. But still table data is empty.
If you are running the command exactly as you have written you have an error:
You have written -no-acl instead of --no-acl and are getting -a that means:
-a, --data-only
Restore only the data, not the schema (data definitions).

Installing postgresql with Homebrew and Rails on Mountain Lion

I have been having a lot of trouble installing Postgresql on my computer.
I have a Rails app that I deploy to Heroku and want to use Postgresql on my local machine. Before I downloaded Postgres.app but never really used it and recently uninstalled it thinking it may be causing some problems.
I install Postgres and every time I run rake db:create:all, I get the following error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I've Googled and tried a bunch of things but have not been able to figure it out and thought I might finally have to get some personal help.
When running which psql I get:
/usr/local/bin/psql
I've tried uninstalling Postgres, uninstalling pg and re-installing it but nothing has been able to work.
Any insight here? Thank you.
IF you are installing it with homebrew did you install the launch daemon so that the server starts up?
look at brew info postgresql
you will need to init the db
initdb /usr/local/var/postgres -E utf8
then start the server
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Then you should be able to create your databases, and use it locally. If you are going to be using it you should follow the directions listed in brew for starting and stopping it automatically..
Try this
psql -U rails -d myapp_development -h localhost
or
psql -U rails -d myapp_development -h 127.0.0.1
For more help see : Can not connect to local PostgreSQL
I have the exactly same problem, try this.
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
More details here.

Resources