pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to execute the sql file in PSQL
5+ messages / 4 participants
[nested] [flat]
* How to execute the sql file in PSQL
@ 2020-10-05 14:55 Mark <jxustnc@gmail.com>
2020-10-05 15:33 ` Re: How to execute the sql file in PSQL Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 5+ messages in thread
From: Mark @ 2020-10-05 14:55 UTC (permalink / raw)
To: pgsql-general
Stackoverflow question link:
https://stackoverflow.com/questions/64210281/using-psql-executing-sql-format-file-shows-permission-d...
I followed one PostgreSQL tutorial step by step. One session to use PSQL to
execute sql files to create a new database in PostgreSQL.
1. copy paste the sql file within "C:\Program Files\PostgreSQL\12"
directory.
2. execute the following code \i C:\\Program
Files\\PostgreSQL\\12\\demo-big-en-20170815.sql
Failed
The message shows C:: Permission denied
then tried \ir "C:\\Program
Files\\PostgreSQL\\12\\demo-big-en-20170815.sql"
Failed
The message shows unrecognized win32 error code: 123"C:/Program
Files/PostgreSQL/12/createdatabasesupertest.sql: Invalid argument
SQL file probably was wrong. SO I tried to create a simple sql file (create
a new database). Then I follow the above mentioned step to execute the
file on windows PSQL. But it failed the same way just like the above
mentioned.
So basically my PSQL can not run script files. What should i do?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: How to execute the sql file in PSQL
2020-10-05 14:55 How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
@ 2020-10-05 15:33 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-05 16:01 ` Re: How to execute the sql file in PSQL Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Adrian Klaver @ 2020-10-05 15:33 UTC (permalink / raw)
To: Mark <jxustnc@gmail.com>; pgsql-general
On 10/5/20 7:55 AM, Mark wrote:
>
>
> Stackoverflow question link:
> https://stackoverflow.com/questions/64210281/using-psql-executing-sql-format-file-shows-permission-d...
>
>
> I followed one PostgreSQL tutorial step by step. One session to use PSQL
> to execute sql files to create a new database in PostgreSQL.
>
> 1. copy paste the sql file within "C:\Program Files\PostgreSQL\12"
> directory.
> 2. execute the following code \i C:\\Program
> Files\\PostgreSQL\\12\\demo-big-en-20170815.sql
>
> Failed
> The message shows C:: Permission denied
> then tried \ir "C:\\Program
> Files\\PostgreSQL\\12\\demo-big-en-20170815.sql"
> Failed
> The message shows unrecognized win32 error code: 123"C:/Program
> Files/PostgreSQL/12/createdatabasesupertest.sql: Invalid argument
>
> SQL file probably was wrong. SO I tried to create a simple sql file
> (create a new database). Then I follow the above mentioned step to
> execute the file on windows PSQL. But it failed the same way just like
> the above mentioned.
>
> So basically my PSQL can not run script files. What should i do?
The issue is the user you are running psql as does not have permissions
to read the file. This is a OS permissions thing. Either run psql as a
user that can read the file or change the permissions on the file to
those that allow the psql user to read it.
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: How to execute the sql file in PSQL
2020-10-05 14:55 How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
2020-10-05 15:33 ` Re: How to execute the sql file in PSQL Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-10-05 16:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-10-06 08:23 ` Re: How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2020-10-05 16:01 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Mark <jxustnc@gmail.com>; pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 10/5/20 7:55 AM, Mark wrote:
>> I followed one PostgreSQL tutorial step by step. One session to use PSQL
>> to execute sql files to create a new database in PostgreSQL.
>> 1. copy paste the sql file within "C:\Program Files\PostgreSQL\12"
>> directory.
>> 2. execute the following code \i C:\\Program
>> Files\\PostgreSQL\\12\\demo-big-en-20170815.sql
>>
>> Failed
>> The message shows C:: Permission denied
> The issue is the user you are running psql as does not have permissions
> to read the file. This is a OS permissions thing. Either run psql as a
> user that can read the file or change the permissions on the file to
> those that allow the psql user to read it.
... or more likely, put the SQL file in a saner place. Dropping random
files into a program directory can only lead to trouble. You should
treat such directories as read-only unless you know exactly what you
are doing.
It seems likely to me that this failure stems from PG being installed
with permissions settings that prevent it from reading/modifying its own
executables, which is good solid security practice.
(If the tutorial actually told you to do that, the tutorial's author
is utterly clueless.)
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: How to execute the sql file in PSQL
2020-10-05 14:55 How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
2020-10-05 15:33 ` Re: How to execute the sql file in PSQL Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-05 16:01 ` Re: How to execute the sql file in PSQL Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-10-06 08:23 ` Mark <jxustnc@gmail.com>
2020-10-06 09:53 ` Re: How to execute the sql file in PSQL Paul Förster <paul.foerster@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Mark @ 2020-10-06 08:23 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
Actually, a single quotation will work.
\ir 'C:\\Program Files\\PostgreSQL\\12\\demo-big-en-20170815.sql'
But I don't know why a single quotation will work.
It would be very helpful if you guys can explain to me.
On Mon, Oct 5, 2020 at 9:31 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 10/5/20 7:55 AM, Mark wrote:
> >> I followed one PostgreSQL tutorial step by step. One session to use
> PSQL
> >> to execute sql files to create a new database in PostgreSQL.
> >> 1. copy paste the sql file within "C:\Program Files\PostgreSQL\12"
> >> directory.
> >> 2. execute the following code \i C:\\Program
> >> Files\\PostgreSQL\\12\\demo-big-en-20170815.sql
> >>
> >> Failed
> >> The message shows C:: Permission denied
>
> > The issue is the user you are running psql as does not have permissions
> > to read the file. This is a OS permissions thing. Either run psql as a
> > user that can read the file or change the permissions on the file to
> > those that allow the psql user to read it.
>
> ... or more likely, put the SQL file in a saner place. Dropping random
> files into a program directory can only lead to trouble. You should
> treat such directories as read-only unless you know exactly what you
> are doing.
>
> It seems likely to me that this failure stems from PG being installed
> with permissions settings that prevent it from reading/modifying its own
> executables, which is good solid security practice.
>
> (If the tutorial actually told you to do that, the tutorial's author
> is utterly clueless.)
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: How to execute the sql file in PSQL
2020-10-05 14:55 How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
2020-10-05 15:33 ` Re: How to execute the sql file in PSQL Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-05 16:01 ` Re: How to execute the sql file in PSQL Tom Lane <tgl@sss.pgh.pa.us>
2020-10-06 08:23 ` Re: How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
@ 2020-10-06 09:53 ` Paul Förster <paul.foerster@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Paul Förster @ 2020-10-06 09:53 UTC (permalink / raw)
To: Mark <jxustnc@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general
Hi Mark,
> On 06. Oct, 2020, at 10:23, Mark <jxustnc@gmail.com> wrote:
>
> Actually, a single quotation will work.
> \ir 'C:\\Program Files\\PostgreSQL\\12\\demo-big-en-20170815.sql'
> But I don't know why a single quotation will work.
> It would be very helpful if you guys can explain to me.
because Microsoft had the glorious idea of putting a blank character into "Program Files". Quoting this will make the whole C:\...sql line one single word which is then passed to \i.
Cheers,
Paul
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2020-10-06 09:53 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 14:55 How to execute the sql file in PSQL Mark <jxustnc@gmail.com>
2020-10-05 15:33 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-10-05 16:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-10-06 08:23 ` Mark <jxustnc@gmail.com>
2020-10-06 09:53 ` Paul Förster <paul.foerster@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox