altering privilege in psql interactive prompt - postgresql

I am new to the use of psql prompt. I ran sudo -u postgres (psql version 9.3.9)
Then I connected to my database and I ran
=> ALTER DEFAULT PRIVILEGES FOR USER some_user IN SCHEMA public GRANT SELECT ON TABLES TO other_user;
and then I got this error message
ERROR: syntax error at or near "ALTER DEFAULT PRIVILEGES FOR USER"
LINE 1: ALTER DEFAULT PRIVILEGES FOR USER ckan_default IN SCHEMA pub..
How can I deal with that ?

Related

psql faild to restor file from network drive

i have a dump file on drive z (network drive)
im opening the psql from PgAdmin4
this is the command that im writeing:
psql -U postgres -d postgres -f Z:\DB_BU\md_20220729.sql
and this is the error that im getting:
Invalid command \DB_BU. Try \? for help.
when im doing this:
psql -U postgres -d postgres -f i\ Z:\DB_BU\md_20220729.sql
Invalid command \DB_BU. Try ? for help.
and when im doing this:
psql -U postgres -d postgres -f "Z:\DB_BU\md_20220729.sql"
im not getting any error but also its not restoring the file. how can i restor the file?
You're trying to call psql from within psql or PGAdmin. Since
psql is a standalone program, not an SQL command you can run in PGAdmin SQL window or psql's own, internal meta-command you're getting the error
Invalid command \DB_BU. Try \? for help
indicating that there was an attempt to interpret your entire command as a SQL query or an internal command and that this attempt failed.
You can open "psql tool" from within PGAdmin but your command won't work there either because it's trying to call psql itself, with some command-line options, which you cannot do when you're already inside an interactive psql session. The command
psql -U postgres -d postgres -f Z:\DB_BU\md_20220729.sql
can be used outside psql and PGAdmin, in your terminal, like zsh on Mac, sh/bash on Linux, cmd or PowerShell on Windows, where psql is installed and visible, along with your network path.
If you're able to open the psql tool window in PGAdmin, you can instead try and use an internal psql \i meta-command which is basically the same thing as the -f command-line option, but meant for use inside the psql session:
\i "Z:\DB_BU\md_20220729.sql"

PostgreSQL - using psql terminal to restore a dump - error: stdin is not a tty

On Windows 10, using psql with PostgreSQL 14 installed, I'm trying to restore a dump that is my_dump.sql.
I'm on Bash terminal currently.
I'm connected to psql server and I created a new database new_db, then a new superuser tobe.
Then I tried the command psql -d new_db < my_dump.sql but I'm getting the error stdin is not a tty
I tried the solution psql -U tobe -d new_db -f my_dump.sql from "stdin is not a tty" when populating Postgres database
because they mention the error but now I get a new error:
ERROR: syntax error at or near "ÿþ" LIGNE 1 : ÿþ
Are the two errors connected? Maybe the second error is only related to the command syntax. I'm not sure if I'm in the right direction.
Try
psql.exe -U tobe -d new_db -f my_dump.sql

Copying local postgresql to AWS RDS

I have a Postgesql database that I want to copy/replicate from my local machine to an AWS RDS instance.
I've created a dump as follows:
pg_dump -v -U postgres mydb > mydb.dump
I then tried to copy to my RDS as follows:
psql -f mydb.dump -h XXXXXXXXXXXX.us-east-1.rds.amazonaws.com -p 5432 -U postgres -d mydb
However, I get the following error:
psql:mydb.dump:1: error: invalid command \
psql:mydb.dump:6: ERROR: syntax error at or near "ÿ_"
LINE 1: ÿ_-"\o""edrp\nou"tnsctme e
^
I then tried to rule out any issues with RDS by copying the archive to another local database as follows:
pg_restore -U postgres -d mydbcopy mydb.dump
I received an error:
pg_restore: error: input file does not appear to be a valid archive
I also tried the preceding as follows:
psql -f my.dump -U postgres -d mydbcopy
And got the same error as before:
psql:mydb.dump:1: error: invalid command \
psql:mydb.dump:6: ERROR: syntax error at or near "ÿ_"
LINE 1: ÿ_-"\o""edrp\nou"tnsctme e
^
I am using Windows Powershell and Postgresql 13.2.
Am I missing something ?
It seems to be an issue with PSQL tools in view that I'm getting the error even when trying to copy locally.
I managed to solve this problem by using
pg_dump -f dump.sql --inserts mydb
It turns out using the redirect ">" means PowerShell does the file writing and it uses UTF16 which doesn't play nice with psql. The -f flag makes pg_dump do the writing itself.

mysqldump command resulting in "error 1064 syntax error"

I’m in the MySQL command line client mysql monitor, trying to do a mysqldump command on the database with which I have an open connection. This is the command I’m using at the mysql> prompt:
mysqldump -u username -p password databasename > dumpfilename.sql\g.
I assume that the file dumpfilename.sql will be created when the dump is successful. I have tried it with and without pw, un, end-of-line semicolon, etc. I am getting
error 1064 syntax error
over and over again. What am I doing wrong?
mysqldump is a program, not a MySQL command. Exit the mysql client and enter the mysqldump -u username -p password databasename > dumpfilename.sql command at the shell prompt and it will work

Unable To Run PSQL

Whenever I try to run 'psql' I receieve the following error message:
ahcarpenter#ubuntu:~$ psql
psql: FATAL: role "ahcarpenter" does not exist
Any ideas on how to fix this?
That happens because
$ psql
is equivalent to
$ psql ahcarpenter -U ahcarpenter
As that user does not exist enter as user postgres
$ psql -U postgres
Once inside create the user and the database "ahcarpenter".
create user ahcarpenter;
create database ahcarpenter with owner ahcarpenter;
exit
\q
Reenter
$ psql