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-20 06:24:17
Message-ID: ~00258F854114E3640002659@walla.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2017-04-20 06:48:32 Unable to upload backups
Previous Message Tom Lane 2017-04-20 05:22:47 Re: referential integrity between elements of an array and another table?