I'm using db2 client in windows to connect to Linux DB2 server.
I'm trying to upload data using my client but the data is in the /tmp/ directory in the host server.
If I use LOAD FROM "/tmp/file.txt" OF .. it fails with message QL2036N The path for the file, named pipe, or device "/tmp/file.txt" is not valid.
It is possible doing thins without db2 connect from the server itself ?
regards
Per comment thread: the solution was to ensure that the Db2-instance owner has read access to the file on the server.
When you use load from then the specified file must reside on the Db2-server, and the Db2-instance owner (e.g. db2inst1) on the server must have read access to the file. DOUBLE CHECK the permissions/ownerships. If the file is on your workstation use load client from.
Related
Using the script below, I was able to load the data to the table with local files.
db2 load from SOME/LOCAL/File.txt of asc modified by reclen=123 method L \(1 11, 12 14\) REPLACE INTO schema.tablename
However, I want to achieve to load the file from another server. I don't want to transfer the files from another server to db2 server so I will be able to use the command as above. Found that DB2REMOTE can be used for remotefiles in this documentation, but I'm not sure how to execute it with success.
Do I need to do this also? Because I don't have the right IAM role and don't have the credentials to do so. If I just can skip this and proceed to connect with another server only.
This is the script I'm trying with DB2REMOTE:
db2 load from 'DB2REMOTE://centos#123.456.789.0:/folders/directory/file.txt' of asc modified by reclen=123 method L \(1 11, 12 14\) REPLACE INTO schema.tablename
Thank you in advance!
DB2REMOTE is for accessing cloud object storage (e.g Amazon S3, IBM Cloud Object Storage), from some Db2 commands.
If you are not using cloud object storage, then mount the remote directory locally with appropriate permissions, and specify the local mountpoint with the Db2 load command .
You can remote mount with SSHFS or similar, when installed and properly configured. This is not programming , but instead it is administration and configuration.
I would like to import a table from the server computer into a Client computer using the copy command. I know this is a recurring issue for users, but I have not been able to get an answer to this particular one and it's also a different scenario, and I believe this to be common.
I used a copy command to copy a Table from the server to the client computer using the code below:
COPY (Select * from Table_Name) TO 'C:\somedirectory\file.csv' DELIMITER ',' CSV HEADER;
However, I got the following
ERROR: relative path not allowed for COPY to file
My question is: How do I use the correct COPY command to copy from the server computer to the client computer in Postgres.
Thank you in anticipation
Please check if your user has read/write access to the destination folder.
This is one thread I found, see if it helps
https://dba.stackexchange.com/questions/158466/relative-path-for-psql-copy-file
https://postgrespro.com/list/thread-id/1116997
Try with network through access using client public IP.
How do I use the correct COPY command to copy from the server computer to the client computer in Postgres
You simply can't.
Which is clearly stated in the manual
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible by the PostgreSQL user (the user ID the server runs as) and the name must be specified from the viewpoint of the server
(emphasis mine)
You need to use psql's \copy command or any other export tool that works on the client side.
I downloaded and installed on Windows the following:
IBM DB2 Runtime Client (64-Bit) 10.5
with the aim of connecting to a remote server database.
It installed here:
C:\Program Files\IBM\SQLLIB
But I don't see any DB2 folders in there.
I tried to catalog the remote db like this:
db2 catalog tcpip node testing remote the.server.com server 446
If I then try to connect to it, I get the following:
SQL1031N The database directory cannot be found on the indicated file system.
There is some wizard installed called the 'Default DB2 and IBM Database Client Interface Selection Wizard'. I ran this and it said it would create a default DB2 copy and would be used by default, called DB2COPY1 and it would be installed to C:\Program Files\IBM\SQLLIB.
But I'm nnot sure what this is doing really.
What do I need to do here to connect to the remote DB2??
EDIT:
I have managed to get a bit further based on this article here:
https://www-01.ibm.com/support/docview.wss?uid=swg21008914
my current commands look like:
db2 catalog tcpip node tstnode remote my.server.com server 446
db2 catalog db db1name as mytstdb at node tstnode authentication server
db2 catalog dcs db db1name as A123456DAT
db2 terminate
db2 connect to mytstdb user <username> using <password>
However the connect fails with:
SQL30061N The database alias or database name "A123456DAT " was not
found at the remote node. SQLSTATE=08004
Any ideas?
If you are connecting through port 446, I guess you are trying to connect to DB2 for IBM z or DB2 for IBM i. If yes, you will need at least Db2 Connect.
Regarding error "SQL30061N The database alias or database name "A123456DAT " was not found at the remote node. SQLSTATE=08004" it happens to me when the userid does not have some priviledges on the source system. If it is an IBM i, look at the corresponding spool file. DRDA Connections are attended by jobs called QRWTSRVR. With the IBM i command WRKSPLF SELECT(USERID) (changing USERID by the user trying the DRDA connection) you can see the spool files for jobs related to your connection. Usually spool file messages are very specific on the cause of the failure.
If you are trying to connect to DB2 on z, I don't have experience.
I am trying to export my Postgres table to a csv on my desktop and I get this error:
ERROR: could not open file "C:\Users\blah\Desktop\countyreport.csv" for writing: Permission denied
SQL state: 42501
This is my query which I believe is the correct syntax
COPY countyreport TO 'C:\\Users\\blah\\Desktop\\countyreport.csv' DELIMITER ',' CSV HEADER;
According to the user manual:
Files named in a COPY command are read or written directly by the
server, not by the client application.
https://www.postgresql.org/docs/current/static/sql-copy.html
The common mistake is to believe that the filesystem access will be that of the (client) user, but it's not. It's normal to run the postgresql server as its own user. Therefore action carried out by the server will be done as a different OS user to the client. The server is usually run as an OS user postgres.
Assuming that you are running the server on your local machine then the simplest way to fix it would be to give postgres access to your home directory or desktop. This can be done by changing the windows security settings on your home directory.
Before you do this.... Stop and think. Is this what you are looking for? If the server is in development then will it always run on the user's machine. If not then you may need to use COPY to write to the stdout. See the manual for information on this.
I'm wondering how I would UNLOAD a file from a SQL Anywhere v10 database onto a client computer. I have multiple servers (30+) at different locations, this is the query I have been using to UNLOAD on a local server:
UNLOAD
SELECT tran, id, amount, date, collection, impacts, type
FROM transactions
ORDER BY tran_num
TO 'C:\Users\administrator\Desktop\Clinic.txt' DELIMITED BY '|'
APPEND ON
QUOTES OFF
I'm looking to modify this to be able to unload from the remote servers but the file to generate at my local/client location where I am sending the query. I am using DtSQL to connect to the database remotely. Anyone have a solution?
share a folder on the client machine and then use the full network path to that client's folder in the unload statement. like '\\targetPC\SharedFolder\Clinic.txt'
or
share a folder on the DB server and then copy the file to your target machine after the unload