I used this command.
psql -U testuser -d testdb -f dump.sql
And I want to know, if it is possible to rollback this command.
Contents of dump.sql are CREATE TABLE, few Inserts into that table and CREATE SEQUNCE, VIEW, DOMAIN.
please someone help me ;-(
Related
I got a MariaDB database dump from a colleague, and he asked me to run it in a docker container.
So i executed the following:
docker pull mariadb:10.4.26
then created the container
docker run --name test_smdb -e MYSQL_ROOT_PASSWORD=<some_password> -p 3306:3306 -d mariadb:10.4.26
then connected to the container:
docker exec -it test_smdb mariadb --user root -p<some_password>
and created a database in it from the mariadb prompt:
MariaDB [(none)]> CREATE DATABASE smdb_dev;
So far, so good. But when i tried to import the dump into it via this command:
docker exec -i test_smdb mariadb -uroot -p<some_password> --force < C:\smdb-dev.sql
i get a lot of lines like
ERROR 1046 (3D000) at line 22: No database selected.
So i am not sure what exactly is the issue?
Should i define a database, in which the dump should be imported? If yes - how exactly, because i look at different pages, like:
https://hub.docker.com/_/mariadb, especially this:
$ docker exec -i some-mariadb sh -c 'exec mariadb -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql
and i see no database mentioned here.
Or
2) The colleague has not created the dump in the correct way?
I do not use mariadb in a docker environment at my place, but I do use mariadb on a linux machine so it should be really similar.
You said you used this command :
docker exec -i test_smdb mariadb -uroot -p<some_password> --force < C:\smdb-dev.sql
If we breakthrough it :
docker exec -i test_smdb docker stuff where you ask docker to execute the following command on the test_smdb container (or close to it, I'm not a docker daily user).
mariadb -uroot -p<password> --force here is the interesting part. You ask your shell to open mariadb and login as root with then given password with an extra flag --force. But you never specify which database should be overridden.
In my gist, again for mariadb outside docker but I really think it should be the same, I've the following command mariadb -uusername -p<password> <DB_NAME> < /path/to/file.sql
So I would try something like :
docker exec -i test_smdb mariadb -uroot -p<some_password> smdb_dev --force < C:\smdb-dev.sql
Below command should work I believe
docker exec -i test_smdb sh -c "exec mariadb -uroot -pPASSWORD smdb_dev" < /some/path/on/your/host/all-databases.sql
Reference: Import local database to remote host Docker container
I have this script with some commands like:
sudo docker exec $container psql -U postgres -c "CREATE DATABASE $gisdb ;"
The $container parameter is no problem, but I cannot get the right value read with $gisdb parameter in the CREATE DATABASE command. Is it possible any other way or do I need to redesign this command or use hardcoded values?
DB name
According to PostgreSQL Documentation, creating database requires name of the database
CREATE DATABASE _name_
So, $gisdb in your code - is the name of the created database.
You might hardcode this name, but you should exactly know - which name you' hardcode.
Because, generally, other services depends on DB name.
So, check the manual of your code.
get rid of sudo
You can omit sudo before docker command.
Just add current user to the docker group:
usermod -aG docker $USER
And then, after login, you'll be able to run docker without sudo
I'm having trouble creating an InfluxDB user in a dockerfile. I want the dockerfile to also install and start influxd. For postgres I can use this in my Dockerfile after installing postgres:
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER matt WITH PASSWORD 'test123';" &&\
createdb test_db &&\
psql --command "GRANT ALL PRIVILEGES ON DATABASE test_db TO matt;"
Is there an equivalent for influxdb?
I ultimately used pieces of the tutumcloud/influxdb repo: the dockerfile starts a shell script that, when it runs, starts influxd in the background, creates an admin user and then foregrounds the influxd process.
My command prompt has the following structure:
psql -d databasename -h hostname -p portnumber -U username -w -f batchfile\location\here
I get the following error:
ERROR: syntax error at or near "ï>>¿"
LINE 1: ï>>¿
This causes the first sql query in the batch to not run.
I don't seem to have any problems when executing a batch file using <. See example below:
psql -d databasename -h hostname -p portnumber -U username -w < batchfile\location\here
I'm running postgreSQL version 8.2.15.
Is there something in the command line or the sql batch that I need when using -f? Thanks in advance!
I have an running on heroku which has data added via the rails admin panel.
I want to have that exact similar data locally on my machine.
With this method I am able to generate the latest dump of that heroku data.
How do I import this dump locally now?
Please help!
Note - I make an app/private directory and ignore it in git, but you can put the dump anywhere you like. I use this sequence of commands to get production data to development.
heroku pg:backups capture --app your_app_name
curl -o private/latest.dump `heroku pg:backups public-url --app your_app_name`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d your_app_development private/latest.dump
Guess you're using postgres and locally you've the postgres installed. Run this command from command line with necessary details, such as hostname, databasename, file name to import the dump sql file.
psql -h hostname -d databasename -U username -f file.sql
// file.sql is the dump file you download from heroku