unable to create new database in DB2 11 - db2

I am using Data Studio 4.1.0.1
and DB2 Version 11.
When i try to create a new DB, I am getting instance not valid error, which however should not be the case, because i can see the instance name in the environment variables, and I am giving the correct name.
Also the instances are running which, the list of valid instances taken from output of db2ilist.exe command
Tried executing via command line..
CREATE DATABASE RD_TEST AUTOMATIC STORAGE YES ON 'C:\' DBPATH ON 'C:\' USING CODESET UTF-8 TERRITORY US COLLATE USING SYSTEM PAGESIZE 8192;
geting error as unexpected token "8192".
How can I create a new DB? is a different version of DS is required for DB2v11?

If you are running that command in the db2cmd.exe window (the window started by db2cwadmin.bat), then you must omit the trailing semicolon. So your full command line would look like:
db2 CREATE DATABASE RD_TEST AUTOMATIC STORAGE YES ON 'C:\' DBPATH ON 'C:\' USING CODESET UTF-8 TERRITORY US COLLATE USING SYSTEM PAGESIZE 8192
As a separate matter, with Db2-LUW it is wise to ensure you are always on the latest build of IBM Data Studio. But that is unrelated to the operation of commands in the regular db2cmd.exe window.

Related

Is there any way to SET client_encoding TO 'UTF8' permanent?

I connect to my db from console using command:
psql -U postgres task_db
and did this select query :
select * from common.task;
I received this Error:
ERROR: character with byte sequence 0xe5 0xb0 0x8f in encoding "UTF8" has no equivalent in encoding "WIN1252"
And followed this command from this answer to fix this: https://stackoverflow.com/a/38487921/7505731
SET client_encoding TO 'UTF8';
It worked.
Problem : Now I have to run above command every time I connect to db from command line. Is there any way I can set this encoding permanent?
You can try to set this command in your .psqlrc file:
Unless it is passed an -X option, psql attempts to read and execute commands from the system-wide startup file (psqlrc) and then
the user's personal startup file (~/.psqlrc), after connecting to the
database but before accepting normal commands. These files can be used
to set up the client and/or the server to taste, typically with \set
and SET commands.
The system-wide startup file is named psqlrc and is sought in the installation's “system configuration” directory, which is most
reliably identified by running pg_config --sysconfdir. By default this
directory will be ../etc/ relative to the directory containing the
PostgreSQL executables. The name of this directory can be set
explicitly via the PGSYSCONFDIR environment variable.
The user's personal startup file is named .psqlrc and is sought in the invoking user's home directory. On Windows, which lacks such a
concept, the personal startup file is named
%APPDATA%\postgresql\psqlrc.conf. The location of the user's startup
file can be set explicitly via the PSQLRC environment variable.
Both the system-wide startup file and the user's personal startup file can be made psql-version-specific by appending a dash and the
PostgreSQL major or minor release number to the file name, for example
~/.psqlrc-9.2 or ~/.psqlrc-9.2.5. The most specific version-matching
file will be read in preference to a non-version-specific file.

How to import a CSV file into PostgreSQL using Mac

I am trying to import data from a CSV file into PostgreSQL using pgAdmin. However, I am getting an error message when attempting to perform a COPY command.
ERROR: could not open file "/Users/brandoncruz/Desktop/Test File.csv" for reading: Permission denied
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.
SQL state: 42501
Below is the code I have attempted to use for the import.
CREATE TABLE roles(
role_id serial PRIMARY KEY,
role_name VARCHAR (255)
);
COPY roles FROM '/Users/brandoncruz/Desktop/Test File.csv' DELIMITER ',' CSV HEADER;
It looks about your permissions. You can change permissions of 'Test File.csv'. I mean Postgres user cannot read your file. After change permissions it must be copied successfully.
You might need to check following path if you are using pgAdmin:
pgAdmin > File > Preferences
Paths > Binary Paths
For postgreSQL binary path, you should find the location of PostgreSQL from your mac and save that:
i.e. C:\Program Files\PostgreSQL\12\bin (Windows)
For mac, check under Applications, Program Files, that depends and changes from Mac to Mac.

A simple COPY statement in PostgreSQL 8.4

I am trying to copy a table's data to a file. I have a small database table in the local windows machine and this code has no problems. When I use this in the development environment (still windows, different database), I get an error.
My standard_conforming_strings is currently off.
This query:
COPY some_table TO 'C:\\temp\\test.csv' WITH CSV HEADER;
Gives this error:
WARNING: nonstandard use of \\ in a string literal
LINE 1: COPY t_table TO 'C:\\temp\\test.csv' WITH CSV HEADER;
^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
ERROR: relative path not allowed for COPY to file
********** Error **********
ERROR: relative path not allowed for COPY to file
SQL state: 42602
I have tried:
'C:\temp\test.csv'
'C:\\temp\\test.csv'
'C:/temp/test.csv'
'C:\/temp\/test.csv'
And in all my test, the caret ^ in the error message points at ^'C:.
You are using PostgreSQL on linux not Windows. Just using a Windows client.
COPY is a server side command. It expects a path on the server. That file is on your Windows client PC so the server cannot access it.
Use \copy from psql instead. Or use PgAdmin's CSV importer.
(Newer PostgreSQL versions would give you a HINT about this in the error message.)

PostgreSQL's COPY statement

Using COPY statement of PostgreSQL, we can load data from a text file into data base's table as below:
COPY CME_ERROR_CODES FROM E'C:\\Program Files\\ERROR_CODES\\errcodes.txt' DELIMITER AS '~'
The above statement is run from a machine which has postgresql client where as the server is in another windows machine. Running the above statement is complaining me that ERROR: could not open file "C:\Program Files\ERROR_CODES\errcodes.txt" for reading: No such file or directory.
After some research, i observed that COPY statement is looking for the loader file(errcodes.txt) in the postgresql server's machine at the same path (C:\Program Files\ERROR_CODES). To test this , i have create the same folder structure in the postgresql server's machine and kept the errcodes.txt file in there. Then the COPY statement worked well. It looks very tough constraint for me with COPY statement.
Is there any setting needed to avoid this? or it is the behavior of COPY statement? I didn't find any information on PostgreSQL documents.
here's the standard solution:
COPY foo (i, j, k) FROM stdin;
1<TAB>2<TAB>3
\.
The data must be properly escaped and tab-separated.
Actually, it is in the docs, even in grammar definition you have STDIN... See: http://www.postgresql.org/docs/9.1/static/sql-copy.html
If you're using some programming language with COPY support, you will have pg_putcopy or similar function. So you don't have to worry about escaping and concatenation.
Hints how to do this manually in Python -> Recreating Postgres COPY directly in Python?
The Perl way -> http://search.cpan.org/dist/DBD-Pg/Pg.pm#COPY_support
Hope this helps.
From the documentation
Quote:
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the server. When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.
If you want to copy from a local machine file to a server use \copy command.

Using COPY FROM in postgres - absolute filename of local file

I'm trying to import a csv file using the COPY FROM command with postgres.
The db is stored on a linux server, and my data is stored locally, i.e. C:\test.csv
I keep getting the error:
ERROR: could not open file "C:\test.csv" for reading: No such file or directory
SQL state: 58P01
I know that I need to use the absolute path for the filename that the server can see, but everything I try brings up the same error
Can anyone help please?
Thanks
Quote from the PostgreSQL manual:
The file must be accessible to the server and the name must be specified from the viewpoint of the server
So you need to copy the file to the server before you can use COPY FROM.
If you don't have access to the server, you can use psql's \copy command which is very similar to COPY FROM but works with local files. See the manual for details.