I am writing a powershell script that outputs a query to a file. After connecting to the database, I get a permission denied error that i am not able to get around. This is a production database, so I cannot modify the existing table schema, just trying to write content to a file. I have also tried running the script below with the postgres (root) account, but had no luck.
Any help would be greatly appreciated.
$DBConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=localhost;Port=5432;Database=PRPC;Uid=id;Pwd=pwd";
$DBCommandText = "copy (select * from table) to
'C:\Users\myUser\Desktop\output.txt' with csv;";
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = $DBCommandText;
$DBCmd.ExecuteReader();
$DBConn.Close();
This depends a bit on the PostgreSQL version and how it was installed.
9.1 and older installed as the postgres operating system user on Windows by default. 9.2 and newer run as NETWORK SERVICE. In both cases you can change that default, e.g. to run under a domain account.
PostgreSQL's COPY command does file I/O as the user account the PostgreSQL server runs under. So that user must have write permission to the destination. Typically one user can't write to another user's home directory, so you're getting an error.
To permit this to work you'll need to create a directory then change its permissions in the Security properties tab so that the user PostgreSQL runs as has the right to write to it. You may also need to change the permissions on its containing directories so that PostgreSQL can read it; I'm not 100% sure of the details in the Windows permissions model, as I work mainly with unix systems.
Related
When I am restoring the database, by default data is going in C drive, but when I installed the db2 that time I specify the path in D drive only.
Also, sample database files created by db2 is stored in D drive.
Can anyone please tell me what is the issue?
I have run this command:
SELECT * FROM SYSIBMADM.DBPATHS
below is the result i fetched:
LOGPATH- D:\DB2\NODE000\SQL00001\SQLOGDIR\
DB_STORAGE_PATH- C:\
LOCAL_DB_DIRECTORY - D:\DB2\NODE000\SQLOGDIR\
DBPATH - D:\DB2\NODE000\SQL00001\
I Want to change this DB_STORAGE_PATH C:\ to D:\ for all the database which i will be restoring.
You can run db2set from db2 command line that will confirm you wheather db2 installed on path with other information;
db2-command-line> db2set
DB2_ATS_ENABLE=YES
DB2_CREATE_DB_ON_PATH=YES
DB2INSTPROF=C:\where\db2\installed\IBM\DB2\DB2COPY1
DB2COMM=TCPIP
You can get more information of Directory structure for your installed DB2 database product (Windows) here
You can run the following command SELECT * FROM SYSIBMADM.DBPATHS. This will give details of following variables of your installed db2 database;
LOGPATH
DB_STORAGE_PATH
LOCAL_DB_DIRECTORY
DBPATH
These commands will provide you enough information to locate your installed database. Then you can restore your database providing the exact path.
To add a storage path to an existing database, issue the following ALTER DATABASE statement:
ALTER DATABASE database-name ADD STORAGE ON storage-path
After adding one or more storage paths to the database, you may use the ALTER TABLESPACE statement to rebalance table spaces in the database so that they start to use the new storage paths immediately.
DB2 has a configuration parameter for the default path for databases, dftdbpath. In addition, the command db2sampl to create a sample database has an option dbpath to specify where to place that database.
db2sample -dbpath D:
The above would place the new database on drive D:.
You will find that there are default paths for certain operations. The overview of DB2 database manager configuration parameters has lists most of them.
For your specific issue I would assume that a parameter was changed some time after DB2 was installed and used initially.
For RESTORE be aware that the options TO and DBPATH are ignored if restoring an existing database.
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.
Running DB2 version 9.7 on Windows Server. I'm new to DB2, but not to databases in general.
My underlying problem is this error in the Event Viewer:
ADM1848W Failed to archive log file "S0000880.LOG" to "USEREXIT" from
"C:\DB2\NODE0000\SQL00003\SQLOGDIR\".
I don't want to user a USEREXIT program.
If I'm understanding what I've read correctly, the new method to specify a log archive method is to use LOGARCHMETH1. However some documentation (and some observed behavior) lead me to believe that it isn't that simple.
My current DB configuration is this:
> get db config for $my_db
....
Log retain for recovery status = RECOVERY
User exit for logging status = YES
....
First log archive method (LOGARCHMETH1) = LOGRETAIN
I'm trying to turn off USEREXIT with this :
update db cfg for $my_db using userexit off
but with no effect.
How can I set my db to use LOGRETAIN but not USEREXIT ?
And a follow up, if I do get this set correctly, is a backup required to complete the change?
Thanks!
Although I don't have a complete understanding of the USEREXIT still, I solved it by turning all logging off, then turning it back on with these steps (db2 commands):
To turn off:
connect to $db
update database configuration for $db using logretain off
db2stop
db2start
Then, turning on on:
connect to $db
update database configuration for $db using logretain on
db2stop
db2start
db2 backup database $db to <filename> without prompting
Note: a backup is NOT required when turning logging OFF but IS REQUIRED when turning logging ON.
I'm trying to setup a local firebird instance to test against but am unable to connect to it with even ISQL. I have tried to following by following the quick start guide here:
CONNECT ..\examples\empbuild\employee.fdb user SYSDBA password masterkey;
Which resulted in:
Statement failed, SQLSTATE = 08001
unavailable database
After some searching I tried modifying that to:
CONNECT "localhost:C:\Program Files\Firebird\Firebird_2_5\examples\empbuild\employee.fdb" user SYSDBA password masterkey;
Which resulted in:
Statement failed, SQLSTATE = 28000
cannot attach to password database
After confirming I had the right directory path I decided to give on on connecting for now and try creating a new DB:
SQL>CREATE DATABASE 'C:\data\test.fdb' page_size 8192
CON>user 'SYSDBA' password 'masterkey';
Which also gave me the error:
Statement failed, SQLSTATE = 08001
unavailable database
Are there any common pitfalls I might be hitting? I've also tried the commands above both with and without the firebird service running. Also is there a detailed reference on the SQLSTATE codes?
As already mentioned in my comments the problem is caused by running the Firebird server as an application. Firebird has its password database (security2.fdb) in C:\Program Files\Firebird\Firebird_2_5. As this database is (almost, but not entirely) a normal Firebird database, the server requires write access to this database (for the transactions, etc).
By default (with UAC) users do not have write access to the password database, so this requires elevation to Administrator. So access to Firebird requires that you either run the application as a service with sufficient rights (eg as done by the default installer), or when running the server as application to run it 'As administrator'. Another option is to not install it in Program Files.
This BTW applies double when accessing the example employee database as this database file is also located in the Program Files folder.
This is for macOS/OSX (mine is 10.15) firebird ver 2.5 users.
The installation process here does not ask for a sysdba password. Which means: the security database 'security2.fdb' does not exist after a new installation.
This seems to be intentionally for security reasons since > ver 2.5.
To create one, we use the demo database as a helper:
open sql as su: >sudo isql (we don't have user rights on dir)
Connect to a existing db:
sql>connect
"/Library/Frameworks/Firebird.framework/Resources/examples/empbuild/employee.fdb
" user 'SYSDBA' password 'masterkey';
Now we created the missing file 'security2.fdb' in the folder:
"/Library/Frameworks/Firebird.framework/Resources/English.lproj/var/"
(jro)
I have some databases on DB2 on an AIX server.
I login as the DB2 instance user id "chandroo" (having the db2profile set automatically when i login) and issue a command as below and get no result.
chandroo#xxxxxxxx::/db2/chandroo> db2 list db directory
chandroo#xxxxxxxx::/db2/chandroo>
However if I invoke the db2 directly from the installation directory I am able to see the entries , and I have no clue as to why it happens.
chandroo#xxxxxxxxx::/opt/IBM/db2/V9.5/bin> ./db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = CHANDB
Database name = CHANDB
Local database directory = /db2/chandroo/db
Database release level = c.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = CHAN
Database name = CHAN
Local database directory = /db2/chandroo/db
Database release level = c.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
chandroo#xxxxxxxxx::/opt/IBM/db2/V9.5/bin>
It sounds like the db2profile script isn't being sourced properly. The environment variables defined in that script need to be set for your current AIX shell process, not a temporary subprocess started by sh, ksh, or bash. This is accomplished by specifying a single dot instead of a program name to run the db2profile script. The difference is subtle, but important.
If that is the problem, running this command will fix the problem by properly initializing your current shell process:
. ~chandroo/sqllib/db2profile
and commands like db2 list db directory will start working.
The next step is to determine what is keeping that from happening in your $HOME/.profile startup script. If you see the call to db2profile using the proper syntax as shown above, there might be a problem with the execution permissions on $HOME/.profile.