Delete and restore postgress database in sikuli - postgresql

I have used below code to delete postgress database. My issue is I am unable to find query which would restore database. Please provide your assistance. thank you!!
from __future__ import with_statement
import sys
from sikuli import *
from com.ziclix.python.sql import zxJDBC
load("C:\\Test\\SikuliX\\postgresql-9.4.1207.jre6")
connection2 = zxJDBC.connect('jdbc:postgresql://127.0.0.1/?stringtype=unspecified', 'postgres', 'pswd#123', 'org.postgresql.Driver')
connection2.autocommit = True
curs = connection2.cursor()
curs.execute('DROP DATABASE IF EXISTS sampledb')
curs.execute( < I need query to restore database>)

There is no "command" to restore a postgresql database. Usually a backup consists of a very large bunch of commands that piece by piece create a database that is mostly identical to what you have backupped before. Your only possibility is to use the shell command pg_restore.
Oh, and your question has nothing to do with sikuli-ide. The problem is programming language agnostic.

Found workaround for this, instead of restore we can copy the database
curs.execute('CREATE DATABASE [newdb] WITH TEMPLATE [originaldb] OWNER dbuser')

Related

How to export and import data from a Postgres database with Hasura?

I have Hasura GraphQL engine running on a Docker container. My goal is to export all the data from my Postgres database so that my coworker can import it and work with the same data. What is the correct way to do this with Hasura?
You can totally do like the normal database on docker, nothing different, you can use any kind of dump or import/export.
You should understand the way Hasura works, it just take database as an input, Hasura does not take the database installation process.

How to load a foodmart database in to postgres

i have installed a PostgreSQL database.Now i need to download and import a food mart database to practice some reporting techniques.I am new to this field so do not know where to start.Please it will be very helpful if anyone can provide me a guidance to start it.
This repo contains the foodmart data loader for Postgres, Mysql, Sqlserver, Sybase
https://github.com/OSBI/foodmart-data
All you need to do is clone it and launch the following script:
sh FoodMartLoader.sh --db postgres
connection props are set inside the script
For Clickhouse DB2 and SAP Hana and some other DBs look at the branches of this
fork:
https://github.com/contiamo/foodmart-data-public

How to Import DB2 full dump

I have a DB2 v9.7 Dump(.gz format) which i need to import to an another DB2 database of same version.
All the tables needs to be imported in one go.
Can somebody help me in how to achieve this ?
Thankyou in adavnce.
-Nitika
First, the DB2 backups do not have that name structure. You should have a file inside that .gz that should have a name like this
SAMPLE.0.db2inst1.NODE0000.CATN0000.20131224235959.001
It gives the database name, the backup type; the instance that host the database; the node (when using DPF); the timestamp; and the file number.
Normally, it just change the timestamp. And in order to restore the db you should go to the directory where the file is, and then just type:
db2 restore db sample
Eventually, if it does not work, you should specify the timestamp, directory or other things:
db2 restore db sample from /dir taken at 20131224235959
If you change the instance, you should rebind some packages. Also, you should be sure that the security structure is the same in the new installation (/etc/passwd and /etc/group have the same users and groups used in DB2)
For more information, please check: http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.admin.ha.doc/doc/c0006237.html
You can use db2move command
db2move sample export
db2move sample import
where sample is the database name.
If you are having .dmp file then you can use below commands import .dmp file.
If you have dmp file in tar or zip you need to extract this.
db2 –c- -svtf db2dump.dmp > log.txt
Note:
It is different then: restore command as below :
restore db from Path_of_the_backup_file.
eg: restore db QAST from C:\Backups\Backup_location
backup db to C:\Backups\Backup_location.
eg: restore db QISST from C:\Backups\Backup_location

How do I load a .pgbackup file locally? with pgAdminIII?

I downloaded a .pgbackup file but couldn't find information on how to load it into a local db.
The forum I grabbed it from is not very responsive too.
Thank you in advance!
Use pg_restore as per the docs
You can use PgAdmin-III to restore a backup too, there's a "Restore" option in the menus. You have to select a database to restore into in order for this option to be enabled, or you can select the "postgres" database and check the option to create a new database for the restored DB in the restore options dialog.
It's also possible that you're dealing with an ordinary SQL dump. If so, you can load it with the command-line psql tool. There is no way I know of to restore an SQL dump via PgAdmin-III. Details of restoring backups with psql are discussed in the documentation.
I wrote a bit of a rant about the usability of backup and restore in PgAdmin-III a while ago.

can we get the postgres db dump using SQLAlchemy?

Is it possible to have the postgres database dump(pg_dump) using SQLAlchemy? i can get the dump using pg_dump but I am doing all other db operations using SQLALchemy and thus want to know if this dump operation is also opssible using SQLAlchemy. Any suggestion, link would be of great help.
Thanks,
Tara Singh
pg_dump is a system command.so I do not think you could have postgres database dump using SQLAlchemy.
SqlAlchemy do not manage sort of pg_dump. You probably can mimic it with a buch of queries but it will be painfull.
The more easy way is to use pg_dump itself inside a python script with os.system or subprocess.call
If it's for regular saves also have a look to safekeep project who speak for you to your databases