How can I copy a .sql file to a Postgresql? - sql

I have installed confluence and postgres on synology nas using docker. Both run succesfully. Now I have to copy the data from a .sql file to the database that I have created in postgres.
How can I do this? I tried looking up different things but nothing helps.
regards

Use could use psql and let read commands from the file and execute this in your database. --file=? will do the trick.

Related

How to create sh script which will run SQL file on CentOS without sqlplus lib

I'd need to create a sh script, which will connect to Oracle DB and then execute a SQL file.
The problem is that sqlplus is not installed on that Cent-OS machine and most probably it won't be installed either.
Is there a way how to do this?
You can easily install Oracle Instant Client including sqlplus executable ("Free to download, deploy and distribute").
See
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
If some java version is installed on the server, you can create a simple class that will connect to oracle DB via JDBC, load the sql script and execute it.
Create and compile java class
Upload class file, sql script + oracle_driver (jar file) (https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html)
Execute the java program
You can’t. You need to install oracle client which include sqlplus or sqlloader.
Or you can use Python and library Cx_Oracle, but you still need sqlclient to connect to database.
If you don’t want to install oracle client, you can use external table to load data to database or some etl tool.

Unable to run .sql file in SQL Server

I have a .sql dump file 20 gb and I am trying to run it on Mysql workbench using run script and after successful execution, using SSMA I'll migrate the data from Mysql workbench to SQL Server. I have migrated the data this way many times successfully however for 20 gb file it seems very time-consuming. Please let me know if there is any alternate way to achieve this quickly. I have followed the following link:
Steps to migrate mysql tables to sql server using SSMA!
From your Title "unable to run .sql file in SSMS" and "I have a .sql dump file 20 gb" are you trying to open a 20GB .sql in SSMS? That's never going to work. SSMS is a 32bit application, so the maximum addressable memory is 2GB. If you want to run your .sql file, I suggest using sqlcmd.
Open up Powershell, and then run the command below replacing the appropriate parts:
sqlcmd -S {Server Name/ServerIP} -U {Your Login} -i {Your full path to your script}
You'll be prompted for your password and then you the file will be run. So, as an example, you might run:
sqlcmd -S svSQL2017 -U Larnu -i \\svFileServer\SQLShare\Scripts\BigBatchFile.sql
If you are using integrated security, then don't pass the -U parameter for the command.
Edit: This answer is no relevant to the OPs question, as they were using "SSMS" as a synonym for SQL Server, which it is not. I have left this here for the moment so the OP can review my comments, and I will likely remove this answer at a later point.

a .sql backup with pqsl won't work

sorry for my stupid question, but I need your help. I have tried everything, but nothing seems to work.
I want to restore a database using pgAdmin 4 and psql on windows 10. I have created a database and an user in pgAdmin 4. Then I open psql and execute set role to and then \i <name.sql>. I always get an error.
No such file or directory.
The file is in
psql C:/Users/hasan/a.sql
I have set a path in pgAdmin C:/Program Files/PostgresSQL/9.6/bin. I have also tried to restore the database with right-click on db in pgAdmin 4. It starts running and nothing happens.
It has been running for hours and hours. The process watcher also doesn't show any information. I don't know what to do. I have tried all solutions from this page and also watched youtube videos. It won't work.
Try
psql -f C:/Users/hasan/a.sql
or from inside psql
\i "C:/Users/hasan/a.sql"

Alternatives to sqlcmd/best practice

I have created a sql query that updates certain tables taking a CSV file as the input.
I want my co-workers to be able to execute this query as easily as possible. At first, I thought a batch file using sqlcmd was the best solution.
The end product works on my computer, because I have SSMS installed, but no other computer is able to properly launch the batch file.
What is the best way for my end-users to run an sql query? I have thought/researched these solutions:
-Install SSMS or the required tools(don't want each user to have to do this.)
-Install Psexec tools to allow for remote batch launching (also don't like this.)
Is there a better way?
Check SQLS*Plus from www.memfix.com - works the best.
Why don't you create a C-Sharp or VB.Net program that executes the proc and distribute the program to your users?
You don't have to install all of SMS. You can just install SQLServer2008CmdLnUtilsx86.msi for SQL 2008 or go here to get SQLCMD for SQL 2012. http://www.microsoft.com/en-us/download/details.aspx?id=36433. Just be aware that if you install SQLCMD in a bat file and then attempt to use SQLCMD after installing it in that same bat file you have to specify full path to SQLCMD because PATH value is loaded at time bat was started and SQLCMD was not yet available at that time.

Sometimes databse is created but sometimes it isn't

I just started with sql using sqlite 3.7.17. I tried reading through here. As suggested I ran
create table test (id);
.quit
commands in sqlite terminal. No .db file was created in the current directory.
Then I tried to read through the documentation and ran
sqlite3 test.db
in the terminal. No .db file was created but sqlite terminal opened up. I ran
;
.quit
in the sqlite terminal and the .db file was created.
I am using Windows 7 and the terminal that I keep talking about is the Windows Powershell. I have placed the binaries for Windows in C:\Windows\system32\ folder so that the terminal recognizes sqlite3.
What did I do wrong? Why was .db file created once?
In the first case you probably ran sqlite3 without specifying a database file, so the program wouldn't know which file to create. In the second case you specified a file, but it isn't created before you're running an actual SQL statement against it (; is an empty SQL statement, but a statement nonetheless).