I need to restore db from dump and cannot do it - psql

I have a database dump at D:/backup.dump. I try to restore my database min_ro: I open psql.exe plugin. There are words
min_ro=#
Then I write restore command:
min_ro=# psql min_ro < D:/backup.dump
Then happens nothing. My database is not restored. What is wrong? It's first time using psql.
Update. I don't need psql only - I need to restore db from dump and cannot do it.

psql is not a SQL statement, so it doesn't make sense to enter that at the psql prompt which is there to run SQL statements (or psql meta commands).
c:\> psql min_ro < D:/backup.dump
needs to be entered on the (Windows) command line, not inside psql.
You can however just run the SQL script (which I assume your dump is) by using the \i ("include") meta command in `psql``
c:\> psql min_ro
min_ro=# \i D:/backup.dump

When you restore your database at pgAdminIII (by right-click at database name then choice 'restore') you can't see .dump files at backup list by default. That was my mistake forced me to try another ways to restore DB from dump.
But if you simply change file types to 'All files' you can restore your database from dump as usially.

Related

Can psql commands be executed from Rails application

I want to know whether psql commands be executed from an Application ?
For example I want to make use of \crosstabview functionality which psql provides. It is a great feature to have when viewing the reports.
I have an application which uses Ruby on Rails. I'm thinking whether I can run the \crosstabview from the application.
These are features of psql application only. There is no way to use them via database driver, be it ActiveRecord or anything else. That's just a different thing.
However, you can have table view using, for example, table_view gem.
Can psql commands be executed from Rails application?
It can theoretically be done by running psql from ruby. Its just a really clunky solution.
The psql --command option only takes a single function name or a SQL string that is parsable by the database and which cannot use psql specific functions. Which means that you can run for example %x{ psql --command "\\h"} but not \crosstableview which needs input.
That leaves using PTY to open an interactive session.
# example using PTY to connect to an interactive psql shell
require 'pty'
require 'expect'
PTY.spawn('psql') do |output, input, pid|
output.expect /\=\#/ do
input.puts '\\conninfo'
output.each do |line|
puts line
end
end
end
While possible there is a much better solution - use the crosstab function from the tablefunc extension which can be used with ActiveRecord::Base.connection.execute.
I managed to do this with "\ir" option provided by psql. By this option, you can run the commands written in a file. So put all commands that you want to run in CLI in a single file.
Now you just have to connect to psql and pass filename to "\i" option.
Example: I created a file "a.rb" and it inlcudes the following-
psql -h localhost -U postgres
\ir filename

How to take dump of neo4j graph databases?

I had my all databases stored at a location C:\JATIN DATA\database\neo4jDatabases. How can I take the dump of all databases individually using neo4j Dekstop.
I had already tried neo4j-admin dump --database= --to= this command but getting errors like Neo.ClientError.Statement.SyntaxError: Invalid input 'n': expected (line 1, column 1 (offset: 0))
"neo4j-admin dump --database= --to="
^
neo4j-admin must be run from a terminal command line -- not from the neo4j Browser.
Since you are using the Desktop, you can open a terminal window to the appropriate directory by selecting your neo4j Project from the Projects panel on the left, click the Manage button of the database you want to dump, And then select the Terminal tab.
Once in the Terminal window, you can enter a command like the one suggested by #logisma:
bin/neo4j-admin dump --database=graph.db --to=c:\
Thanks #cybersam and #logisima finally dump is taken successfully. This is the complete command .\bin\neo4j-admin.bat dump --database=graph.db --to=c:\dump\article_citation_graph.dump there was some admin privilege error.
Have you try this : .\bin\neo4j-admin.bat dump --database=graph.db --to=c:\
This should create a file named graph.db.dump in your c:\ folder.

Hyperledger Explorer

I have installed all prerequisites for setting up the hyperledger Explorer but when I start it, I got the following error in log file:
And my config.json file is this:
Postgres' command also done:
1: https://i.stack.imgur.com/eTpSY.png
2: https://i.stack.imgur.com/IocQU.png
You're database setup is not done correctly, run these commands one by one.
Database setup
Connect to PostgreSQL database
sudo -u postgres psql
Run create database script
\i app/db/explorerpg.sql
\i app/db/updatepg.sql
Run db status commands.
\l view created fabricexplorer database
\d view created tables
Actually it postgres database error ...
In your error its clearly said that the chaincode_id doesnt exit ... so this is the problem .
if you want check what column are existed in the transaction table just follow below step
cd blockchain-explorer/app/persistence/postgreSQL/db
sudo -u postgres psql
\d transactions
check the corresponding column chaincode_id exist or not (it wont exist now ,Thats why you got this error)....
Solution for this type error
If you got any error like this first just go to the blockchain-explorer/app/persistence/postgreSQL/db directory
There you can see two file explorerpg.sql and updatepg.sql open this two file and check the corresponding column if existed on any of this file or not. If not you better to download explorer another version which contain the corresponding columns either of this two file mentioned above.
if existed just run below command on ubuntu
cd blockchain-explorer/app/persistence/postgreSQL/db
sudo -u postgres psql
\i explorerpg.sql
\i updatepg.sql
Once done this command just check the column "chaincode_id " is created or not by
\d transactions
it will list all column just check it on.
if the chaincode_id is exist run the explorer again ....

How to dump data from mysql database to postgresql database?

I have done the depot application using mysql... Now i am in need to use postgres... So i need to dump data from mysql database "depot_development" to postgres database "depot_develop"...
Here you can find some interesting links http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL#MySQL
Have you tried to copy the tables from one database to the other:
a) export the data from MySQL as a CSV file like:
$> mysql -e "SELECT * FROM table" -h HOST -u USER -p PWD -D DB > /file/path.csv'
and then,
b) import it into Postgres like:
COPY table FROM '/file/path.csv' WITH CSV;
This question is a little old but a few days ago i was dealing with this situation and found pgloader.io.
This is by far the easiest way of doing it, you need to install it, and then run a simple lisp script (script.lips) with the following 3 lines:
/* content of the script.lisp */
LOAD DATABASE
FROM mysql://dbuser#localhost/dbname
INTO postgresql://dbuser#localhost/dbname;
/*run this in the terminal*/
pgload sctipt.lisp
And after that your postgresql DB will have all of the information that you had in your MySQL SB
On a side note, make you you compile pgloader since at the time of this post, the installer has a bug. (version 3.2.0)

Importing mysql procedures generated from mysqldump --routines

I use the mysqldump tool to make copies of my database. The problem is, when I use the --routines parameter to output my stored procedures along with my data, the generated output causes an error when I try to import it.
It goes something like this:
% mysqldump --routines MyDB | mysql MyDB2
(where MyDB2 already exists but is empty)
The error I get is the following:
ERROR 1064 (42000) at line 307: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 23
Everything works correctly if I omit the --routines.
Has anyone else encountered this?
I was able to get this to work by splitting it into two calls:
% mysqldump MyDB | mysql MyDB2
% mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt MyDB | mysql MyDB2
If something's erroring when running the queries in MyDB2, it's best to:
Run mysqldump to save the output to a saved file.
Run the file bit by bit, to identify which part has the problem.
Fix that bit.
I once had a problem like this where I was exporting from an old version of mysql and importing into a newer one, which had declared one of my column names a reserved word. Are your two databases on different servers running different versions of mysql? Or is there some other difference between the databases (e.g. character set)?

Resources