Getting "Access is denied" error when executing pg_dump on Windows - postgresql

I'm trying to execute pg_dump for one of my PostgreSQL databases, but I am having permission problems.
C:\Windows\system32>pg_dump -U postgres -p 1863 -O social_sense > C:\\Program Files\\PostgreSQL\\8.4\\data\\social_sense.sql
I am getting the following error:
Access is denied
Can anyone enlighten?

I apologise for taking up your time. It was due to that there is no write permission to the directory i was writing to.

Or you can run the cmd as administrator. In my situation that solved the problem too. I know it is a bit late answer but I thought, it would help someone else maybe

Related

Heroku postgres populate file permission denied

I Get this error message when I try to give my postgres heroku backend an sql file to init the database.
I've tried to change permissions of the file and give it all read and write. I don't know what the problem is.
I suspect it's postgres/sql related but I don't know what to do.
simao#simao-kde-neon:~/Desktop/t1g1$ heroku pg:psql postgresql-colorful-03183 -a differ-backend < init.sql
--> Connecting to postgresql-colorful-03183
could not read from input file: Permission denied
▸ psql exited with code 1
I believe that the Heroku pg utilities use your own local installation of postgres under the hood. Looking at that error, it seems like whichever user runs psql locally doesn't have permissions for init.sql. Try chmod on the sql file to make sure that the correct user has permission to read the file.

ERM from PostgreSQL via psql (SQL Shell)

I need to understand the relations between tables in a PostgreSQL database. I will not have the ability to download pgAdmin4 like I am used to working in. So after looking around I found pg_dump.exe built into PostgreSQL. I thought I could just do something like this in the SQL Shell (psql) to get a dump of the database and then have the ability to upload it into another system:
database=# pg_dump database > path/to/save/file.sql;
Based on the docs >> https://www.postgresql.org/docs/9.3/app-pgdump.html
But when I run that I get an error:
ERROR: syntax error at or near "pg_dump"
LINE 1: pg_dump database > path/to/save/file.sql;
^
I saw on this stack overflow question was similar to my issue with the pg_dump error. In the solutions, Adrian says that pg_dump does not work within psql. When I run the code that Adrian suggested, I also get an error.
Any thoughts on how I can use psql to get the information that I need of this database?
Note: I am accessing a Linux VM on a Windows machine.

SQL shell (psql) permission denied

Before i ask you a question please understand if my question is not well asked. This is my first time using psql. Well, i tried to start the server with shell and there isn't any other databases as you see and they are all default. However it doesn't ask me for password and it occured an error as you see in the code. what do i have to do to fix this issue?
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
find: /c/pagefile.sys: Permission denied
Just open sqlshell in administrator. My problem solved by this.

psql: FATAL: could not open file "base/11951/11717": Read-only file system

I'm trying to access the postgreSQL database from CLI. When I login as postgres and enter command
I'm getting error
psql: FATAL: could not open file "base/11951/11717": Read-only file system
I'm new to this. Any pointers on where to look at would be a great help. TIA
Seems like the VM where the database was hosted went to Read-only mode for an unknown issue.
$ fsck
command helped to repair linux filesystems and was able to access psql db.
Most likely your system has detected disk errors and put the filesystem in read-only mode to protect its self from possible corruption.
Check dmesg and the kernel log files.
I strongly advise you to read and act on https://wiki.postgresql.org/wiki/Corruption .
Sometimes It indicates that the server had a general error...(Happened to me yesterday, the moment the server was restarted, the "FATAL: could not open file" disappeared.

postgres could not stat file <basexxxx/xxxx> Permission denied

This is a problem using stats(), or just when calculating the database size. Using postgresql in windows 7, localhost.
The problem after doing this is:
"could not stat file "base/17436/119145": Permission denied"
I spent a lot of time trying to fix this problem, until i realise what is really the problem about.
So i'm going to answer myself.
This could be for 2 reasons:
-User of database (login role) without enough permissions.
In this case, check if the user, for example "postgres", have all the controls and privileges active.
-If localhost, check your antivirus, Twice.
Statistics made by postgresql might be considered as a virus movement by many antiviruses (ESET in my case), is a false positive, the only solution is to locate the directory of the database (like \PostgreSQL\9.3\data) and create am exception to that directory in your antivirus software.
As you can see, this second option is not related to the database code it self.
Hope this help you.
In my case (as #JB suggested) restarting the PostgreSQL service will work in some instances.
in my case I got this error after broke an "reindexdb.exe database" command with Ctrl-C. I was running it on Windows 7 command prompt.
Stop-Start of the PostgreSQL service solved the problem.