Re: Unable to upload backups

From: Ron Ben <ronb910(at)walla(dot)co(dot)il>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, "<pgsql-general(at)postgresql(dot)org>" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unable to upload backups
Date: 2017-04-19 14:16:37
Message-ID: ~00258F77145372D8900210E@walla.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<div><div dir="rtl"><div dir="ltr">
<div dir="rtl">
<div dir="ltr">Here :)</div>
<div dir="ltr">I think I may have found the problem.</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">The role defined as:</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">CREATE ROLE "ronb" LOGIN<br>&nbsp; NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;<br>GRANT users TO "ronb";</div>
<div dir="ltr">GRANT users2 TO "ronb";</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">users is a group role:</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">CREATE ROLE users <br>&nbsp; SUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION;</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">&nbsp;users2 is a group role:</div>
<div dir="ltr">CREATE ROLE users2 <br>&nbsp; NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;</div>
<div dir="ltr">GRANT reports TO users2 ;</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">&nbsp;</div>
<div dir="ltr">I think PostgreSQL doesn't know how to handle this conflicted commands.</div>
<div dir="ltr">What PostgreSQL does when such conflic appears? does it take the last known command of grant?</div>
</div>
<br>Sadly, when there are more than one role it's impossible to know which role was first. PostgreSQL shows them alphabeticly rather than by date so in case of overlaping instructions its impossible to know which one was first.<br><br></div></div><section class="cust_msg_end"></section><blockquote style="margin:0;margin-bottom:20px;border-top:1px solid #e0e0e0;"><br>ב אפר׳ 19, 2017 17:01, Adrian Klaver כתב:<blockquote style="margin:0;margin-bottom:20px;border-top:1px solid #e0e0e0">On 04/19/2017 06:49 AM, Ron Ben wrote:<br><br>Is it possible to get your email program to left justify text on <br>sending? I can figure out the right justified text, it just takes me longer.<br><br>&gt; I think I may have found the problem.<br>&gt;<br>&gt; The role defined as:<br>&gt;<br>&gt; CREATE ROLE "ronb" LOGIN<br>&gt; NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;<br>&gt; GRANT users TO "ronb";<br>&gt; GRANT users2 TO "ronb";<br>&gt;<br>&gt; users is a group role:<br>&gt;<br>&gt; CREATE ROLE users<br>&gt; SUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION;<br>&gt;<br>&gt; users2 is a group role:<br>&gt; CREATE ROLE users2<br>&gt; NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;<br>&gt; GRANT reports TO users2 ;<br><br>That may or may not be the problem. See:<br><br><a href="https://www.postgresql.org/docs/9.6/static/sql-createrole.html">https://www.postgresql.org/docs/9.6/static/sql-createrole.html</a><br><br>"The INHERIT attribute governs inheritance of grantable privileges (that <br>is, access privileges for database objects and role memberships). It <br>does not apply to the special role attributes set by CREATE ROLE and <br>ALTER ROLE. For example, being a member of a role with CREATEDB <br>privilege does not immediately grant the ability to create databases, <br>even if INHERIT is set; it would be necessary to become that role via <br>SET ROLE before creating a database."<br><br><br>What you show above is part of the answer. The other parts are the <br>actual privileges on the objects. Also the command that created the dump <br>file that you are trying to restore. Permissions/privileges issues can <br>be complex and solving them requires a complete set of information.<br><br>&gt;<br>&gt;<br>&gt; I think PostgreSQL doesn't know how to handle this conflicted commands.<br>&gt; What PostgreSQL does when such conflic appears? does it take the last<br>&gt; known command of grant?<br>&gt;<br>&gt; Sadly, when there are more than one role it's impossible to know which<br>&gt; role was first. PostgreSQL shows them alphabeticly rather than by date<br>&gt; so in case of overlaping instructions its impossible to know which one<br>&gt; was first.<br>&gt;<br>&gt;<br>&gt; ב אפר׳ 19, 2017 16:40, Adrian Klaver כתב:<br>&gt;<br>&gt; On 04/19/2017 03:56 AM, Ron Ben wrote:<br>&gt; &gt; Hi,<br>&gt; &gt; I'm using PostgreSQL 9.3.2<br>&gt; &gt; I'm running the command:<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; psql -h testserver -U ronb -f backup.sql -q -d foldertest<br>&gt; 2&gt;error.txt<br>&gt; &gt;&gt;output.txt<br>&gt;<br>&gt; What was the command that created backup.sql?<br>&gt;<br>&gt; &gt;<br>&gt; &gt; This should generate my database in foldertest<br>&gt; &gt;<br>&gt; &gt; However this doesn't work. It's unable to create schemas<br>&gt; &gt;<br>&gt; &gt; in the error.txt i see "permission denied for database<br>&gt; foldertest".<br>&gt;<br>&gt; What user is the foldertest owner?<br>&gt;<br>&gt; In psql l will tell you this.<br>&gt;<br>&gt; &gt;<br>&gt; &gt; I know this is not an access permission issue because there is<br>&gt; a public<br>&gt; &gt; schema which is buildin and it does create the tables/data in<br>&gt; there.<br>&gt;<br>&gt; Because the public schema is by default open to all:<br>&gt;<br>&gt; <a href="https://www.postgresql.org/docs/9.6/static/ddl-schemas.html">https://www.postgresql.org/docs/9.6/static/ddl-schemas.html</a><br>&gt;<br>&gt; "A user can also be allowed to create objects in someone else's<br>&gt; schema.<br>&gt; To allow that, the CREATE privilege on the schema needs to be<br>&gt; granted.<br>&gt; Note that by default, everyone has CREATE and USAGE privileges<br>&gt; on the<br>&gt; schema public. This allows all users that are able to connect to<br>&gt; a given<br>&gt; database to create objects in its public schema. ... "<br>&gt;<br>&gt;<br>&gt; &gt;<br>&gt; &gt; It just cant create new schemas.<br>&gt;<br>&gt; In psql do dn+, that will show schema owners and who else has<br>&gt; privileges.<br>&gt;<br>&gt; For what the different privileges are and how they are<br>&gt; represented in<br>&gt; the above output see:<br>&gt;<br>&gt; <a href="https://www.postgresql.org/docs/9.6/static/sql-grant.html">https://www.postgresql.org/docs/9.6/static/sql-grant.html</a><br>&gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; The intresting thing is that if I do:<br>&gt; &gt;<br>&gt; &gt; psql -h testserver -U postgres -f backup.sql -q -d foldertest<br>&gt; &gt; 2&gt;error.txt &gt;output.txt<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Everything works. It create all schemas and generate the<br>&gt; database correctly.<br>&gt;<br>&gt; Because the postgres user is a superuser and can do anything.<br>&gt;<br>&gt; &gt;<br>&gt; &gt; I don't see any diffrent in the hba.conf between postgres and<br>&gt; ronb users.<br>&gt;<br>&gt; That is not the issue. pg_hba determines who can connect, what<br>&gt; you are<br>&gt; seeing is the Postgres privilege system determining what a user<br>&gt; can do<br>&gt; once they are connected. If it had been a pg_hba rejection you<br>&gt; would<br>&gt; have seen something like:<br>&gt;<br>&gt; aklaver(at)tito:~&gt; psql -d production -U guest -h localhost<br>&gt; psql: FATAL: no pg_hba.conf entry for host "::1", user "guest",<br>&gt; database "production", SSL on<br>&gt; FATAL: no pg_hba.conf entry for host "::1", user "guest", database<br>&gt; "production", SSL off<br>&gt;<br>&gt;<br>&gt; To get an overview of what users there are in your database<br>&gt; cluster in<br>&gt; psql do du<br>&gt;<br>&gt;<br>&gt; &gt;<br>&gt; &gt; What can be the problem?<br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt; --<br>&gt; Adrian Klaver<br>&gt; adrian(dot)klaver(at)aklaver(dot)com<br>&gt;<br>&gt;<br>&gt; --<br>&gt; Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)<br>&gt; To make changes to your subscription:<br>&gt; <a href="http://www.postgresql.org/mailpref/pgsql-general">http://www.postgresql.org/mailpref/pgsql-general</a><br>&gt;<br>&gt;<br>&gt;<br><br><br>-- <br>Adrian Klaver<br>adrian(dot)klaver(at)aklaver(dot)com<br><br><br>-- <br>Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)<br>To make changes to your subscription:<br><a href="http://www.postgresql.org/mailpref/pgsql-general">http://www.postgresql.org/mailpref/pgsql-general</a><br><br><br></blockquote></blockquote><br></div>

Attachment Content-Type Size
unknown_filename text/html 8.5 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexandre 2017-04-19 14:18:59 Recover corrupted data
Previous Message Adrian Klaver 2017-04-19 14:01:00 Re: Unable to upload backups