Uploading dump file to PostgreSQL - sql

i am totally new to postgresql and i have database as dump file on postgresql which i need to restore/upload it back.. i didnt dumped the file its already available online. I read the documentation of restore command on postgresql but it didnt work w me and i am not sure from the steps that I should follow to successfully upload it!! Please if anyone has an idea or could at least refer me to a really good resources for how to do it I will really appreciate it

Usually its as simple as:
psql dbname < infile
or if it's a custom-format dump:
pg_restore --dbname mydb infile

Related

Data migration from cocroachdb to postgresql

I am tryig to migrate my cockroachdb into postgresql for some reason :
I have dumbs of cockroachdb data in .sql format like booking.sql etc .
I tried many ways ways to solve this problem
tried direct import of dump file using psql but since the dump file was of cockroachdb it is showing some syntactical error
my second plan was to restore the dump file back into cockroachdb system and try running pgdump from there. But I am not able to restore the database in cockroachdb.
ERROR: failed to open backup storage location: unsupported storage scheme: "" - refer to docs to find supported storage schemes
I tried doing again with import statement from cockroachdb but of no use .
with my little knowledge I also searched google and youtube but of their little documentation I didnt found anything useful
Any help will be appreciated . Thank you
for exporting data from cockroachDB there are some limitations. you can't export your data into SQL directly in new versions.
the first way of exporting is using the cockroach dump command, but it's been deprecated from version 20.2 so if you are using a newer version, this won't work.
cockroach dump <database> <table> <table...> <flags>
sample:
cockroach dump startrek --insecure --user=maxroach > backup.sql
in new versions, you can export your data into CSV files using SQL commands like EXPORT
EXPORT DATABASE bank INTO 's3://{BUCKET NAME}/{PATH}?AWS_ACCESS_KEY_ID={KEYID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}' \ AS OF SYSTEM TIME '-10s';
to export into local nodes
EXPORT DATABASE bank INTO ('nodelocal://1/{PATH}');
the other alternative way of exporting is using database clients such as DBeaver.
you can download and install DBeaver from https://dbeaver.io/download/.
after adding the connection you can export the database from this path Right-click on db>tools>Backup
the fastest and easiest way of exporting is using a database tool like DBeaver.
I hope this answer would have been helpful

Is there an alternative way to import data into Postgres than using psql?

I am under strict corporate environment and don't have access to Postgres' psql. Therefore I can't do what's shown e.g. in the SO Convert SQLITE SQL dump file to POSTGRESQL. However, I can generate the sqlite dump file .sql. The resulting dump.sql file is 1.3gb big.
What would be the best way to import this data into Postgres? I also have DBeaver and can connect to both databases simultaneously but unfortunately can't do INSERT from SELECT.
I think the term for that is 'absurd', not 'strict'.
DBeaver has an 'execute script' feature. But who knows, maybe it will be blocked.
EnterpriseDB offers binary downloads. If you unzip those to a local drive you might be able to execute psql from the bin subdirectory.
If you can install psycopg2 or pg8000 for python, you should be able to connect to the database and then loop over the dump file sending each line to the database with cur.execute(line) . It might take some fiddling if the dump file has any multi-line commands, but the example you linked to doesn't show any of those.

How to load chinook database in SQLite

I want to load chinook database in SQLite but I have no idea how can I do that.
First, I used this command but it just made a file without anything in it:
sqlite3 chinook.db
I also downloaded this archive that contains chinook database but I couldn't find chinook.db file to open it with this command:
.open chinook.db
If you have a copy of the chinook database then just use the restore database feature.
cd /home/sqlite
mv sample.db sample.db.old
sqlite3 sample.db < sample.bak
For more information go to http://www.ibiblio.org/elemental/howto/sqlite-backup.html
We should script the database before using it. Here is the link that discussed the whole procedure.

Running psql with pgAdmin4

I try to open a csv file in PGadmin4 with COPY.
However it does not work.
The permission is denied and suggests me to use \copy from pgsql.
I tried to replace COPY by \copy, did not work.
I guess that pgsql must be run another way. I saw there ,example with \copy, that it run with a shell file .sh. However I'm using Windows.
How to run pgsql request ?
Thank you
Try Import/Export option in pgAdmin4 to import your CSV data into Table.
Ref: https://www.pgadmin.org/docs/pgadmin4/dev/import_export_data.html
I answer you on my own question page. Yes, psql is the SQL Shell program and you could start it from the Postgresql folder (from where you start pgAdmin). You do not need of psql if you use pgAdmin.

How to restore SQL Server database

I am playing with MySQL but reading this post before
https://blog.stackoverflow.com/2011/04/creative-commons-data-dump-apr-11/.
I want to play with this data in SQL Server.
When I download them I found many rar files there. When I extract one of them, I found the xml file but I really do not know how I can restore them.
Can anyone can explain what I need to do to restore them.
You can do this from shell command/command line
$ mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]
http://www.webcheatsheet.com/SQL/mysql_backup_restore.php