Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread Kyotaro HORIGUCHI
Thank you for the new patch.

At Fri, 11 Nov 2016 16:42:43 +0900, Michael Paquier  
wrote in 
> On Fri, Nov 11, 2016 at 12:28 AM, Stephen Frost  wrote:
> > We should probably include in here that we may skip a checkpoint if no
> > activity has happened, meaning that this is a safe setting to set for
> > environments which are idle for long periods.
> 
> OK, here is the interesting bit I just updated (I cut the diff a bit
> as the rest is just reformatting):
>  parameter is greater than zero, the server will switch to a new
>  segment file whenever this many seconds have elapsed since the last
>  segment file switch, and there has been any database activity,
> -including a single checkpoint.  (Increasing
> -checkpoint_timeout will reduce unnecessary
> -checkpoints on an idle system.)
> [...]
> +including a single checkpoint.  Checkpoints can however be skipped
> +if there is no database activity, making this parameter a safe
> +setting for environments which are idle for a long period of time.
> 
> > (I'm thinking embedded systems here).
> 
> (Those are most of my users :{) ).

Ok, (FWIW..,) it seems fine for me.

> On Fri, Nov 11, 2016 at 3:23 AM, David Steele  wrote:
> > On 11/10/16 1:03 PM, Stephen Frost wrote:
> >> Agreed. You certainly may wish to log checkpoints, even on an embedded
> >> or low I/o system, but logging that nothing is happening doesn't seem
> >> useful except perhaps for debugging.
> >
> > Sure, DEBUG1 or DEBUG2 makes sense.
> 
> OK. LOG was useful to avoid noise when debugging the thing, but DEBUG1
> is fine for me as well in the final version.

Agreed. DEBUG2 seems too deep for it.

Well, I think we had the final comment and it has been addressd
so I mark this as ready for committer soon.

Thank you all.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread Michael Paquier
On Fri, Nov 11, 2016 at 12:28 AM, Stephen Frost  wrote:
> * Michael Paquier (michael.paqu...@gmail.com) wrote:
>> Thanks for the review! Waiting for a couple of days more is fine for
>> me. This won't change much. Attached is v15 with the fixes you
>> mentioned.
>
> I figured I'd go ahead and start looking into this (and it's pretty easy
> for me to discuss it with David, given he works in the same office ;).

Thanks!

> A couple initial comments:
>
>> diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
>> index adab2f8..38c2385 100644
>> --- a/doc/src/sgml/config.sgml
>> +++ b/doc/src/sgml/config.sgml
>> @@ -2826,12 +2826,9 @@ include_dir 'conf.d'
>>  parameter is greater than zero, the server will switch to a new
>>  segment file whenever this many seconds have elapsed since the last
>>  segment file switch, and there has been any database activity,
>> -including a single checkpoint.  (Increasing
>> -checkpoint_timeout will reduce unnecessary
>> -checkpoints on an idle system.)
>> -Note that archived files that are closed early
>> -due to a forced switch are still the same length as completely full
>> -files.  Therefore, it is unwise to use a very short
>> +including a single checkpoint.  Note that archived files that are
>> +closed early due to a forced switch are still the same length as
>> +completely full files.  Therefore, it is unwise to use a very short
>>  archive_timeout  it will bloat your archive
>>  storage.  archive_timeout settings of a minute or so are
>>  usually reasonable.  You should consider using streaming 
>> replication,
>
> We should probably include in here that we may skip a checkpoint if no
> activity has happened, meaning that this is a safe setting to set for
> environments which are idle for long periods.

OK, here is the interesting bit I just updated (I cut the diff a bit
as the rest is just reformatting):
 parameter is greater than zero, the server will switch to a new
 segment file whenever this many seconds have elapsed since the last
 segment file switch, and there has been any database activity,
-including a single checkpoint.  (Increasing
-checkpoint_timeout will reduce unnecessary
-checkpoints on an idle system.)
[...]
+including a single checkpoint.  Checkpoints can however be skipped
+if there is no database activity, making this parameter a safe
+setting for environments which are idle for a long period of time.

> (I'm thinking embedded systems here).

(Those are most of my users :{) ).

On Fri, Nov 11, 2016 at 3:23 AM, David Steele  wrote:
> On 11/10/16 1:03 PM, Stephen Frost wrote:
>> Agreed. You certainly may wish to log checkpoints, even on an embedded
>> or low I/o system, but logging that nothing is happening doesn't seem
>> useful except perhaps for debugging.
>
> Sure, DEBUG1 or DEBUG2 makes sense.

OK. LOG was useful to avoid noise when debugging the thing, but DEBUG1
is fine for me as well in the final version.
-- 
Michael
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index adab2f8..d2a8ec2 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2826,17 +2826,16 @@ include_dir 'conf.d'
 parameter is greater than zero, the server will switch to a new
 segment file whenever this many seconds have elapsed since the last
 segment file switch, and there has been any database activity,
-including a single checkpoint.  (Increasing
-checkpoint_timeout will reduce unnecessary
-checkpoints on an idle system.)
-Note that archived files that are closed early
-due to a forced switch are still the same length as completely full
-files.  Therefore, it is unwise to use a very short
-archive_timeout  it will bloat your archive
-storage.  archive_timeout settings of a minute or so are
-usually reasonable.  You should consider using streaming replication,
-instead of archiving, if you want data to be copied off the master
-server more quickly than that.
+including a single checkpoint.  Checkpoints can however be skipped
+if there is no database activity, making this parameter a safe
+setting for environments which are idle for a long period of time.
+Note that archived files that are closed early due to a forced switch
+are still the same length as completely full files.  Therefore, it is
+unwise to use a very short archive_timeout  it will
+bloat your archive storage.  archive_timeout settings of
+a minute or so are usually reasonable.  You should consider using
+streaming replication, instead of archiving, if you want data to
+be copied off the master server more quickly than that.
 This 

Re: [HACKERS] Floating point comparison inconsistencies of the geometric types

2016-11-10 Thread Kyotaro HORIGUCHI
Hello,

> Aside from that, I'd like to comment this patch on other points
> later.

The start of this patch is that the fact that most of but not all
geometric operators use fuzzy comparson. But Tom pointed out that
the fixed fuzz factor is not reasonable but hard to find how to
modify it.

We can remove the fuzz factor altogether but I think we also
should provide a means usable to do similar things. At least "is
a point on a line" might be useless for most cases without any
fuzzing feature. (Nevertheless, it is a problem only when it is
being used to do that:) If we don't find reasonable policy on
fuzzing operations, it would be the proof that we shouldn't
change the behavior.


The 0001 patch adds many FP comparison functions individually
considering NaN. As the result the sort order logic involving NaN
is scattered around into the functions, then, you implement
generic comparison function using them. It seems inside-out to
me. Defining ordering at one place, then comparison using it
seems to be reasonable.


The 0002 patch repalces many native operators for floating point
numbers by functions having sanity check. This seems to be
addressing to Tom's comment. It is reasonable for comparison
operators but I don't think replacing all arithmetics is so.  For
example, float8_div checks that

 - If both of operands are not INF, result should not be INF.
 - If the devident is not exactly zero, the result should not be zero.

The second assumption is wrong by itself. For an extreme case,
4.9e-324 / 1.7e+308 becomes exactly zero (by underflow). We
canont assert it to be wrong but the devedent is not zero. The
validity of the result varies according to its meaning. For the
case of box_cn,

> center->x = float8_div(float8_pl(box->high.x, box->low.x), 2.0);
> center->y = float8_div(float8_pl(box->high.y, box->low.y), 2.0);

If the center somehow goes extremely near to the origin, it could
result in a false error.

> =# select @@ box'(-8e-324, -8e-324), (4.9e-324, 4.9e-324)';
> ERROR:  value out of range: underflow

I don't think this underflow is an error, and actually it is a
change of the current behavior without a reasonable reason. More
significant (and maybe unacceptable) side-effect is that it
changes the behavior of ordinary operators. I don't think this is
acceptable. More consideration is needed.

> =# select ('-8e-324'::float8 + '4.9e-324'::float8) / 2.0;
> ERROR:  value out of range: underflow



In regard to fuzzy operations, libgeos seems to have several
types of this kind of feature. (I haven't looked closer into
them). Other than reducing precision seems overkill or
unappliable for PostgreSQL bulitins. As Jim said, can we replace
the fixed scale fuzz factor by precision reduction? Maybe, with a
GUC variable (I hear someone's roaring..) to specify the amount
defaults to fit the current assumption.

https://apt-browse.org/browse/ubuntu/trusty/universe/i386/libgeos++-dev/3.4.2-4ubuntu1/file/usr/include/geos/geom/BinaryOp.h

/*
 * Define this to use PrecisionReduction policy
 * in an attempt at by-passing binary operation
 * robustness problems (handles TopologyExceptions)
 */
...
 * Define this to use TopologyPreserving simplification policy
 * in an attempt at by-passing binary operation
 * robustness problems (handles TopologyExceptions)
(seems not activated)
...
 * Use common bits removal policy.
 * If enabled, this would be tried /before/
 * Geometry snapping.
...
/*
 * Use snapping policy
 */


regards,


-- 
Kyotaro Horiguchi
NTT Open Source Software Center




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Do we need use more meaningful variables to replace 0 in catalog head files?

2016-11-10 Thread Corey Huinker
On Thu, Nov 10, 2016 at 6:41 PM, Tom Lane  wrote:

> I think you've fundamentally missed the point here.  A data dump from a
> table would be semantically indistinguishable from the lots-o-DATA-lines
> representation we have now.  What we want is something that isn't that.
> In particular I don't see how that would let us have any extra level of
> abstraction that's not present in the finished form of the catalog tables.
>

I was thinking several tables, with the central table having column values
which we find semantically descriptive, and having lookup tables to map
those semantically descriptive keys to the value we actually want in the
pg_proc column. It'd be a tradeoff of macros for entries in lookup tables.


> I'm not very impressed with the suggestion of making a competing product
> part of our build dependencies, either.
>

I don't see the products as competing, nor did the presenter of
https://www.pgcon.org/2014/schedule/events/736.en.html (title: SQLite:
Protégé of PostgreSQL). That talk made the case that SQLite's goal is to be
the foundation of file formats, not an RDBMS. I do understand wanting to
minimize build dependencies.


> If we wanted to get into build
> dependency circularities, we could consider using a PG database in this
> way ... but I prefer to leave such headaches to compiler authors for whom
> it comes with the territory.
>

Agreed, bootstrapping builds aren't fun. This suggestion was a way to have
a self-contained format that uses concepts (joining a central table to
lookup tables) already well understood in our community.


Re: [HACKERS] postgres_fdw : altering foreign table not invalidating prepare statement execution plan.

2016-11-10 Thread Ashutosh Bapat
>
> That leaves the question of whether it's worth detecting table-level
> option changes this way, or whether we should just handle those by forcing
> a relcache inval in ATExecGenericOptions, as in Amit's original patch in
> <5702298d.4090...@lab.ntt.co.jp>.  I kind of like that approach; that
> patch was short and sweet, and it put the cost on the unusual path (ALTER
> TABLE) not the common path (every time we create a query plan).
>

You seemed not sure about this solution per [1]. Do you think we
should add similar cache invalidation when foreign server and FDW
options are modified?

> That leaves not much of this patch :-( though maybe we could salvage some
> of the test cases.
>

If that's the best way, we can add testcases to that patch.

[1] https://www.postgresql.org/message-id/29681.1459779...@sss.pgh.pa.us

-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Patch: Implement failover on libpq connect level.

2016-11-10 Thread Tsunakawa, Takayuki
From: pgsql-hackers-ow...@postgresql.org
> [mailto:pgsql-hackers-ow...@postgresql.org] On Behalf Of Robert Haas
> Great, committed.  There's still potentially more work to be done here,
> because my patch omits some features that were present in Victor's original
> submission, like setting the failover timeout, optionally randomizing the
> order of the hosts, and distinguishing between master and standby servers;
> Victor, or anyone, please feel free to submit separate patches for those
> things.

I did a few tests with ECPG.  I'm satisfied with the current behavior, but 
someone says different.  I'd like to share the result.

The following literal connection strings succeeded.  host1 is a server where 
PostgreSQL is not running, and host2 is where it's running.  I could connect to 
the database server on host2.

EXEC SQL CONNECT TO 'tcp:postgresql://host1,host2:5450/postgres';
EXEC SQL CONNECT TO 'tcp:postgresql://host1,host2:5450,5450/postgres';

EXEC SQL CONNECT TO 'postgres@host1,host2:5450';
EXEC SQL CONNECT TO 'postgres@host1,host2:5450,5450';


EXEC SQL CONNECT TO 'tcp:postgresql://?service=my_service';

~/.pg_service.conf
[my_service]
host=host1,host2
port=5450  # and port=5450,5450 case
dbname=postgres


But this one makes PQconnectdbParams() fail, because the passed "host" is 
"host1:5450,host2" and "port" is "5450".  ECPGconnect()'s parser is different 
from libpq's.  However, the tcp:postgresql:// syntax is not described a URL in 
the manual, so I think it's sufficient to just describe the syntax in the ECPG 
article.

EXEC SQL CONNECT TO 'tcp:postgresql://host1:5450,host2:5450/postgres';


And without the single quote like below, ecpg fails to precompile the source 
file.  I also think it's enough to state in the manual "quote the connection 
target if you specify multiple hosts or ports".

EXEC SQL CONNECT TO tcp:postgresql://host1,host2:5450,5450/postgres;

connect.ec:12: ERROR: syntax error at or near ","


Comments?


Regards
Takayuki Tsunakawa


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Calculation of param_source_rels in add_paths_to_joinrel

2016-11-10 Thread Ashutosh Bapat
On Sat, Nov 5, 2016 at 2:16 AM, Tom Lane  wrote:
> Ashutosh Bapat  writes:
>> There's code in add_paths_to_joinrel() which computes the set of
>> target relations that should overlap parameterization of any proposed
>> join path.
>> ...
>> The calculations that follow are based on joinrel->relids (baserels
>> covered by the join) and SpecialJoinInfo list in PlannerInfo. It is
>> not based on specific combination of relations being joined or the
>> paths being generated. We should probably do this computation once and
>> store the result in the joinrel and use it multiple times. That way we
>> can avoid computing the same set again and again for every pair of
>> joining relations and their order. Any reasons why we don't do this?
>
> I'm not terribly excited about this.  The issue is strictly local to
> add_paths_to_joinrel, but putting that set in a global data structure
> makes it nonlocal, and makes it that much harder to tweak the algorithm
> if we think of a better way.  (In particular, I think it's not all that
> obvious that the set must be independent of which two subset relations
> we are currently joining.)

Right now it appears that for every subset of relations, we have
different param_source_rels, which is clearly not. It takes a bit of
time to understand that. Adding it to a global data structure will at
least make the current implementation clear i.e param_source_rels does
not change with subset of relations being joined.

>
> If you can show a measurable performance improvement from this change,
> then maybe those downsides are acceptable.  But I do not think we should
> commit it without a demonstrated performance benefit from the added
> complexity and loss of flexibility.

I couldn't find a measurable time difference with or without my patch,
so multiple computations of param_source_rels aren't taking noticeable
time. I used following queries to measure the planning time through
explain analyze.

create view pc_view as select c1.oid c1o, c2.oid c2o, c3.oid c3o from
pg_class c1, pg_class c2 left join pg_class c3 on (c2.oid = c3.oid)
where c1.oid = c2.oid and c1.oid = c3.oid and c1.relname = c3.relname;
select v1, v2, v3 from pc_view v1, pc_view v2 left join pc_view v3 on
(v2.c3o = v3.c1o), pc_view v4 where v1.c3o = v2.c2o and v1.c2o =
v4.c3o limit 0;

>
>> Also, the way this code has been written, the declaration of variable
>> sjinfo masks the earlier declaration with the same name. I am not sure
>> if that's intentional, but may be we should use another variable name
>> for the inner sjinfo. I have not included that change in the patch.
>
> Hmm, yeah, that's probably not terribly good coding practice.

Attached a patch to fix this.
-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c
index cc7384f..8815789 100644
--- a/src/backend/optimizer/path/joinpath.c
+++ b/src/backend/optimizer/path/joinpath.c
@@ -124,42 +124,42 @@ add_paths_to_joinrel(PlannerInfo *root,
 	 * is a join order restriction that prevents joining one of our input rels
 	 * directly to the parameter source rel instead of joining to the other
 	 * input rel.  (But see allow_star_schema_join().)	This restriction
 	 * reduces the number of parameterized paths we have to deal with at
 	 * higher join levels, without compromising the quality of the resulting
 	 * plan.  We express the restriction as a Relids set that must overlap the
 	 * parameterization of any proposed join path.
 	 */
 	foreach(lc, root->join_info_list)
 	{
-		SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(lc);
+		SpecialJoinInfo *lc_sjinfo = (SpecialJoinInfo *) lfirst(lc);
 
 		/*
 		 * SJ is relevant to this join if we have some part of its RHS
 		 * (possibly not all of it), and haven't yet joined to its LHS.  (This
 		 * test is pretty simplistic, but should be sufficient considering the
 		 * join has already been proven legal.)  If the SJ is relevant, it
 		 * presents constraints for joining to anything not in its RHS.
 		 */
-		if (bms_overlap(joinrel->relids, sjinfo->min_righthand) &&
-			!bms_overlap(joinrel->relids, sjinfo->min_lefthand))
+		if (bms_overlap(joinrel->relids, lc_sjinfo->min_righthand) &&
+			!bms_overlap(joinrel->relids, lc_sjinfo->min_lefthand))
 			extra.param_source_rels = bms_join(extra.param_source_rels,
 		   bms_difference(root->all_baserels,
-	 sjinfo->min_righthand));
+  lc_sjinfo->min_righthand));
 
 		/* full joins constrain both sides symmetrically */
-		if (sjinfo->jointype == JOIN_FULL &&
-			bms_overlap(joinrel->relids, sjinfo->min_lefthand) &&
-			!bms_overlap(joinrel->relids, sjinfo->min_righthand))
+		if (lc_sjinfo->jointype == JOIN_FULL &&
+			bms_overlap(joinrel->relids, lc_sjinfo->min_lefthand) &&
+			!bms_overlap(joinrel->relids, lc_sjinfo->min_righthand))
 			extra.param_source_rels = 

Re: [HACKERS] Transactions involving multiple postgres foreign servers

2016-11-10 Thread Masahiko Sawada
On Wed, Nov 2, 2016 at 9:22 PM, Ashutosh Bapat
 wrote:
> On Mon, Oct 31, 2016 at 6:17 AM, Masahiko Sawada  
> wrote:
>> On Fri, Oct 28, 2016 at 3:19 AM, Robert Haas  wrote:
>>> On Wed, Oct 26, 2016 at 2:00 AM, Masahiko Sawada  
>>> wrote:
 I think we can consider the atomic commit and the atomic visibility
 separately, and the atomic visibility can build on the top of the
 atomic commit.
>>>
>>> It is true that we can do that, but I'm not sure whether it's the best 
>>> design.
>>
>> I'm not sure best design, too. We need to discuss more. But this is
>> not a particular feature for the sharing solution. The atomic commit
>> using 2PC is useful for other servers that can use 2PC, not only
>> postgres_fdw.
>>
>
> I think, we need to discuss the big picture i.e. architecture for
> distributed transaction manager for PostgreSQL. Divide it in smaller
> problems and then solve each of them as series of commits possibly
> producing a useful feature with each commit. I think, what Robert is
> pointing out is if we spend time solving smaller problems, we might
> end up with something which can not be used to solve the bigger
> problem. Instead, if we define the bigger problem and come up with
> clear subproblems that when solved would solve the bigger problem, we
> may not end up in such a situation.
>
> There are many distributed transaction models discussed in various
> papers like [1], [2], [3]. We need to assess which one/s, would suit
> PostgreSQL FDW infrastructure and may be specifically for
> postgres_fdw. There is some discussion at [4]. It lists a few
> approaches, but I could not find a discussion on pros and cons of each
> of them, and a conclusion as to which of the approaches suits
> PostgreSQL. May be we want to start that discussion.

Agreed. Let's start discussion.
I think that it's important to choose what type of transaction
coordination we employ; centralized or distributed.

> I know that it's hard to come up with a single model that would suit
> FDWs or would serve all kinds of applications. We may not be able to
> support a full distributed transaction manager for every FDW out
> there. It's possible that because of lack of the big picture, we will
> not see anything happen in this area for another release. Given that
> and since all of the models in those papers require 2PC as a basic
> building block, I was of the opinion that we could at least start with
> 2PC implementation. But I think request for bigger picture is also
> valid for reasons stated above.

2PC is a basic building block to support the atomic commit and there
are some optimizations way in order to reduce disadvantage of 2PC. As
you mentioned, it's hard to support a single model that would suit
several type of FDWs. But even if it's not a purpose for sharding,
because many other database which could be connected to PostgreSQL via
FDW supports 2PC, 2PC for FDW would be useful for not only sharding
purpose. That's why I was focusing on implementing 2PC for FDW so far.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Patch: Implement failover on libpq connect level.

2016-11-10 Thread Tsunakawa, Takayuki
From: pgsql-hackers-ow...@postgresql.org
> [mailto:pgsql-hackers-ow...@postgresql.org] On Behalf Of Mithun Cy
> Yes this patch will only address failover to new master, values "master"
> and "any" appeared sufficient for that case.

Do you mean that unlike pgJDBC "standby" and "prefer_standby" are useless, or 
they are useful but you don't have time to implement it and want to do it in 
the near future?  Do you mind if I do it if time permits me?  I think they are 
useful without load balancing feature, when the user has multiple standbys for 
HA.

Could you add a new entry in CommitFest 2017-1? I'm afraid we can't track the 
status of your patch because the original patch in this thread has already been 
committed.

Regards
Takayuki Tsunakawa
 


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH] Send catalog_xmin separately in hot standby feedback

2016-11-10 Thread Craig Ringer
On 25 October 2016 at 00:19, Petr Jelinek  wrote:

>> Now formatted a series:
>>
>> 1.  Send catalog_xmin in hot standby feedback protocol
>
>> + xmin_epoch = nextEpoch;
>>   if (nextXid < xmin)
>> - nextEpoch--;
>> + xmin_epoch --;
>> + catalog_xmin_epoch = nextEpoch;
>> + if (nextXid < catalog_xmin)
>> + catalog_xmin_epoch --;
>
> Don't understand why you keep the nextEpoch here, it's not used anywhere
> that I can see, you could just as well use the xmin_epoch directly if
> that's how you want to name it.

Fixed, thanks.

>> + /*
>> +  * A 10.0+ standby's walsender passes the lowest catalog xmin of any
>> +  * replication slot up to the master.
>> +  */
>> + feedbackCatalogXmin = pq_getmsgint(_message, 4);
>> + feedbackCatalogEpoch = pq_getmsgint(_message, 4);
>>
>
> I'd be more interested to know why this is sent rather than it's sent
> since version 10+ in this comment.

Removed. It's explained in a comment inside the if
(hot_standby_feedback) block in walreceiver anyway.

>> 2.  Make walsender respect catalog_xmin in hot standby feedback messages
>
>> + if (TransactionIdIsNormal(feedbackCatalogXmin)
>> + && TransactionIdPrecedes(feedbackCatalogXmin, 
>> feedbackXmin))
>> + {
>> + MyPgXact->xmin = feedbackCatalogXmin;
>> + }
>> + else
>> + {
>> + MyPgXact->xmin = feedbackXmin;
>> + }
>
> This not how we usually use the {} brackets (there are some more
> instances of using them for one line of code in this particular commit).

Whoops. Thanks. I find the Pg convention pretty ghastly when dealing
with multi-line 'if' conditions followed by a single-line statement,
but it's still the convention whether I like it or not.

>> 3.  Allow GetOldestXmin(...) to optionally disregard the catalog_xmin
>> By ignoring slot catalog_xmin in the GetOldestXmin() call then
>> separately calling ProcArrayGetReplicationSlotXmin() to get the
>> catalog_xmin to  we might produce a catalog xmin slightly later than
>> what was in the procarray at the time we previously called
>> GetOldestXmin() to examine backend/session state. ProcArrayLock is
>> released so it can be advanced in-between the calls. That's harmless -
>> it isn't necessary for the reported catalog_xmin to be exactly
>> consistent with backend state. If it advances it's safe to report the
>> new position since we know the confirmed positions are on-disk
>> locally.
>>
>> The alternative here is to extend GetOldestXmin() to take an out-param
>> to report the slot catalog xmin. That really just duplicates  the
>> functionality of ProcArrayGetReplicationSlotXmin but means we can grab
>> it within a single ProcArray lock. Variants of GetOldestXmin and
>> ProcArrayGetReplicationSlotXmin that take an already-locked flag would
>> work too, but would hold the lock across parts of GetOldestXmin() that
>> currently don't retain it. I could also convert the current boolean
>> param ignoreVacuum into a flags argument instead of adding another
>> boolean. No real preference from me.
>>
>
> I would honestly prefer the change to GetOldestXmin to return the
> catalog_xmin. It seems both cleaner and does less locking.

Fair enough. Done.

> In general it's simpler patch than I expected which is good. But it
> would be good to have some tests.

Agreed. OK, I've added basic tests for physical replication slots and
hot_standby_feedback to t/001_stream_rep.pl since it make sense to
test both along with stream_rep.pl's tests of cascading, etc and I
don't think a separate test is needed.

It's not actually practical to add tests for the catalog_xmin on
standby functionality until the next patch in the series (pending)
which enables logical decoding on standby. Currently you can't create
a slot on a standby so you can't cause the standby to hold down
catalog_xmin. But the tests show things work how they should within
the range of currently exposed functionality.

In the process I noticed how skeletal those tests still are. We have a
great framework now (thanks Michael!) and I'd like to start filling it
out with tests involving unclean shutdowns, promotions, etc. There's a
lot still to write to get solid coverage. Tests aren't hard. Who's
keen to write some? I'll happily help any volunteers out.

New patch series attached. 0001 is the new tests. The guts is patches
2-5. I'm not sure whether 2, 3, 4 and 5 should be squashed for commit
or not, but I left them separate for easier review.

For complete functionality this series will want to be coupled with
logical decoding timeline following and a pending patch to enable
logical decoding on standby.

-- 
 Craig Ringer   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
From 80964a3b4f6a98f83a123f69924f2627d89c7a5b Mon Sep 17 00:00:00 2001
From: Craig 

Re: [HACKERS] Microvacuum support for Hash Index

2016-11-10 Thread Ashutosh Sharma
Hi Jesper,

> Some initial comments.
>
> _hash_vacuum_one_page:
>
> +   END_CRIT_SECTION();
> +   _hash_chgbufaccess(rel, metabuf, HASH_READ, HASH_NOLOCK);
>
> The _hash_chgbufaccess() needs a comment.
>
> You also need a place where you call pfree for so->killedItems - maybe in
> hashkillitems().

Thanks for reviewing this patch. I would like to update you that this
patch has got dependency on a patch for concurrent hash index and WAL
log in hash index. So, till these two patches for hash index are not
stable I won't be able to share you a next version of patch for
supporting microvacuum in hash index.

With Regards,
Ashutosh Sharma
EnterpriseDB: http://www.enterprisedb.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread leoaaryan
Hi Michael,

Thanks for all the help and time. I have already developed a code where I
can exactly calculate the to be allocated shared memory value based on the
Postgres 9.5.4 code (i went through the code, found out the sizes and offset
of all the structures used in the memory calculation process and then use
the values from postgres.conf file to calculate the required value).

But the problem is if there is any change in the structures or anything is
newly added in the next major version, I need to look at the code again and
see what changed and then modify the hardcoded values of the structure size.
I'm trying to avoid that.

-leoaaryan



--
View this message in context: 
http://postgresql.nabble.com/Shared-memory-estimation-for-postgres-tp5929868p5929891.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: [BUGS] BUG #14350: VIEW with INSTEAD OF INSERT TRIGGER and COPY. Missing feature or working as designed.

2016-11-10 Thread Haribabu Kommi
On Fri, Nov 11, 2016 at 6:15 AM, Tom Lane  wrote:

> Haribabu Kommi  writes:
> > [ copy_to_view_3.patch ]
>
> Pushed with cosmetic adjustments.
>

Thank you.


Regards,
Hari Babu
Fujitsu Australia


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread Michael Paquier
On Fri, Nov 11, 2016 at 1:26 PM, leoaaryan  wrote:
> I think the method "pg_get_shmem_allocations" mentioned in the patch will
> give the allocated shared memory when the postgres db server is running. I'm
> trying to get the same without running the server if possible.

That's up to "read the code and create a formula based on the system
parameter to calculate the amount" then.
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Danger of automatic connection reset in psql

2016-11-10 Thread Pavel Stehule
2016-11-11 5:14 GMT+01:00 Ashutosh Bapat :

> >
> > How about, instead of all this, adding an option to psql to suppress
> > the automatic reconnect behavior?  When enabled, psql just exits
> > instead of trying to reconnect.
> >
> +1. But, existing users may not notice addition of the new option and
> still continue to face problem. If we add the option and make it
> default not to reconnect, they will notice it and use option to get
> older behaviour, but that will break applications relying on the
> current behaviour. Either way, users will have at least something to
> control the connection reset.
>

The reconnect in not interactive mode is a bad idea - and there should be
disabled everywhere (it cannot to break any application - the behave of
script when a server is restarted must be undefined (100% if ON_ERROR_STOP
is active). In interactive mode it can be controlled by some psql session
variables like AUTOCOMMIT.

Regards

Pavel


>
>
>
> --
> Best Wishes,
> Ashutosh Bapat
> EnterpriseDB Corporation
> The Postgres Database Company
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread leoaaryan
Hi Craig,

Sorry for the multiple point of contact for the same question. I'll keep in
mind to attach similar corresponding links in future if any.

http://stackoverflow.com/questions/39607940/is-it-possible-to-know-the-memory-being-allocated-by-the-method-createsharedmem
and
http://stackoverflow.com/questions/40433784/is-it-possible-to-call-a-postgres-internal-method-from-a-util
are the other two posts from my side on stackoverflow to understand more
about the feasibility of the nature of task I'm trying to accomplish.





--
View this message in context: 
http://postgresql.nabble.com/Shared-memory-estimation-for-postgres-tp5929868p5929887.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread leoaaryan
Hi Michael,

I think the method "pg_get_shmem_allocations" mentioned in the patch will
give the allocated shared memory when the postgres db server is running. I'm
trying to get the same without running the server if possible.

Please correct me if I have failed to understand the discussion thread
contents.



--
View this message in context: 
http://postgresql.nabble.com/Shared-memory-estimation-for-postgres-tp5929868p5929886.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Danger of automatic connection reset in psql

2016-11-10 Thread Ashutosh Bapat
>
> How about, instead of all this, adding an option to psql to suppress
> the automatic reconnect behavior?  When enabled, psql just exits
> instead of trying to reconnect.
>
+1. But, existing users may not notice addition of the new option and
still continue to face problem. If we add the option and make it
default not to reconnect, they will notice it and use option to get
older behaviour, but that will break applications relying on the
current behaviour. Either way, users will have at least something to
control the connection reset.



-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread Craig Ringer
On 11 November 2016 at 06:57, leoaaryan  wrote:
> I am a newbie to databases and Postgres and I am trying to analyze the shared
> memory being calculated and allocated by Postgres in the method
> "CreateSharedMemoryAndSemaphores" for different major versions for different
> postgres.conf file

Note that this follows on from a number of other posts, including

http://stackoverflow.com/questions/39607940/is-it-possible-to-know-the-memory-being-allocated-by-the-method-createsharedmem

http://stackoverflow.com/questions/40433784/is-it-possible-to-call-a-postgres-internal-method-from-a-util

Please, PLEASE link to related prior discussion when you post
somewhere. It's really annoying having to look it up or wasting
people's time duplicating discussion that's already happened.


-- 
 Craig Ringer   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Unlogged tables cleanup

2016-11-10 Thread Michael Paquier
On Thu, Nov 10, 2016 at 10:52 PM, Kuntal Ghosh
 wrote:
> On Thu, Nov 10, 2016 at 3:42 PM, Michael Paquier
>  wrote:
>> Nah. Looking at the code the fix is quite obvious.
>> heap_create_init_fork() is checking for XLogIsNeeded() to decide if
>> the INIT forknum should be logged or not. But this is wrong, it needs
>> to be done unconditionally to ensure that the relation gets created at
>> replay.
>
> I think that we should also update other *buildempty() functions as well.
> For example, if the table has a primary key, we'll encounter the error again
> for btree index.

Good point. I just had a look at all the AMs: bloom, btree and SP-gist
are plainly broken. The others are fine. Attached is an updated patch.

Here are the tests I have done with wal_level = minimal to test all the AMs:
\! rm -rf /Users/mpaquier/Desktop/tbsp/PG*
create extension bloom;
create extension btree_gist;
create extension btree_gin;
create tablespace popo location '/Users/mpaquier/Desktop/tbsp';
set default_tablespace = popo;
create unlogged table foo (a int);
insert into foo values (generate_series(1,1));
create index foo_bt on foo(a);
create index foo_bloom on foo using bloom(a);
create index foo_gin on foo using gin (a);
create index foo_gist on foo using gist (a);
create index foo_brin on foo using brin (a);
create unlogged table foo_geo (a box);
insert into foo_geo values ('(1,2),(2,3)');
create index foo_spgist ON foo_geo using spgist(a);

-- crash PG
-- Insert some data
insert into foo values (100);
insert into foo_geo values ('(50,12),(312,3)');

This should create 8 INIT forks, 6 for the indexes and 2 for the
tables. On HEAD, only 3 are getting created and with the patch all of
them are.
-- 
Michael
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index 0946aa2..c9c7049 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -164,13 +164,12 @@ blbuildempty(Relation index)
 	metapage = (Page) palloc(BLCKSZ);
 	BloomFillMetapage(index, metapage);
 
-	/* Write the page.  If archiving/streaming, XLOG it. */
+	/* Write the page and log it. */
 	PageSetChecksumInplace(metapage, BLOOM_METAPAGE_BLKNO);
 	smgrwrite(index->rd_smgr, INIT_FORKNUM, BLOOM_METAPAGE_BLKNO,
 			  (char *) metapage, true);
-	if (XLogIsNeeded())
-		log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
-	BLOOM_METAPAGE_BLKNO, metapage, false);
+	log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
+BLOOM_METAPAGE_BLKNO, metapage, false);
 
 	/*
 	 * An immediate sync is required even if we xlog'd the page, because the
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 128744c..624aa84 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -242,13 +242,12 @@ btbuildempty(Relation index)
 	metapage = (Page) palloc(BLCKSZ);
 	_bt_initmetapage(metapage, P_NONE, 0);
 
-	/* Write the page.  If archiving/streaming, XLOG it. */
+	/* Write the page and log it */
 	PageSetChecksumInplace(metapage, BTREE_METAPAGE);
 	smgrwrite(index->rd_smgr, INIT_FORKNUM, BTREE_METAPAGE,
 			  (char *) metapage, true);
-	if (XLogIsNeeded())
-		log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
-	BTREE_METAPAGE, metapage, false);
+	log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
+BTREE_METAPAGE, metapage, false);
 
 	/*
 	 * An immediate sync is required even if we xlog'd the page, because the
diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index 01c8d21..8ac3b00 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -161,13 +161,12 @@ spgbuildempty(Relation index)
 	page = (Page) palloc(BLCKSZ);
 	SpGistInitMetapage(page);
 
-	/* Write the page.  If archiving/streaming, XLOG it. */
+	/* Write the page and log it. */
 	PageSetChecksumInplace(page, SPGIST_METAPAGE_BLKNO);
 	smgrwrite(index->rd_smgr, INIT_FORKNUM, SPGIST_METAPAGE_BLKNO,
 			  (char *) page, true);
-	if (XLogIsNeeded())
-		log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
-	SPGIST_METAPAGE_BLKNO, page, false);
+	log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
+SPGIST_METAPAGE_BLKNO, page, false);
 
 	/* Likewise for the root page. */
 	SpGistInitPage(page, SPGIST_LEAF);
@@ -175,9 +174,8 @@ spgbuildempty(Relation index)
 	PageSetChecksumInplace(page, SPGIST_ROOT_BLKNO);
 	smgrwrite(index->rd_smgr, INIT_FORKNUM, SPGIST_ROOT_BLKNO,
 			  (char *) page, true);
-	if (XLogIsNeeded())
-		log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
-	SPGIST_ROOT_BLKNO, page, true);
+	log_newpage(>rd_smgr->smgr_rnode.node, INIT_FORKNUM,
+SPGIST_ROOT_BLKNO, page, true);
 
 	/* Likewise for the null-tuples root page. */
 	SpGistInitPage(page, SPGIST_LEAF | SPGIST_NULLS);
@@ -185,9 +183,8 @@ spgbuildempty(Relation index)
 	PageSetChecksumInplace(page, SPGIST_NULL_BLKNO);
 	smgrwrite(index->rd_smgr, INIT_FORKNUM, SPGIST_NULL_BLKNO,
 			  (char 

Re: [HACKERS] Floating point comparison inconsistencies of the geometric types

2016-11-10 Thread Kyotaro HORIGUCHI
Hello,

> > Returning to the issue, the following query should give you the
> > expected result.
> >
> > SELECT name, #thepath  FROM iexit ORDER BY name COLLATE "C", 2;
> 
> Yes, I have worked around it like this.  What I couldn't understand is
> how my patch can cause this regression.  How is it passes on master
> without COLLATE?

Ah, sorry, I understand that *you* added the COLLATE.  Revering
select_views.sql/out to master actually causes a regression error.

The reason for that is that you forgot to edit an alternative
exptect file, which matches for en_US locale.

But the test doesn't for collation and the only difference
between the alternative expect files comes from the difference of
collation for the query. "the workaround" seems to be the right
way to do it. I recommend rather to leave the workaroud as it is
and remove select_views_1.out from the "expected" directory.

Aside from that, I'd like to comment this patch on other points
later.

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread Michael Paquier
On Fri, Nov 11, 2016 at 8:40 AM, leoaaryan  wrote:
> The easiest way to find the value for the shared memory computation is to
> change the logging level to DEBUG3 and start postgres DB engine and it will
> give the calculated value in the log file.
>
> I believe postgres as a DB needs to be running for any extension to run (I
> may be wrong here) and I dont want to start the database for this analysis.
>
> Please correct me if I'm wrong in my concepts or if I've not understood
> anything.

Some time ago a patch has been proposed to project to a system view
the shared memory allocations currently happening on an instance:
https://www.postgresql.org/message-id/20140504114417.gm12...@awork2.anarazel.de
This could be plugged into its own extension rather easily. Note
though that DSM segments (dynamic shared memory) do not have names
associated to them which would be helpful if you'd like to track that
as well. But perhaps you don't care much.
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Remove the comment on the countereffectiveness of large shared_buffers on Windows

2016-11-10 Thread Tsunakawa, Takayuki
From: pgsql-hackers-ow...@postgresql.org
> [mailto:pgsql-hackers-ow...@postgresql.org] On Behalf Of Magnus Hagander
Okay and I think partially it might be because we don't have
> writeback
>   optimization (done in 9.6) for Windows.  However, still the broader
>   question stands that whether above data is sufficient to say that
> we
>   can recommend the settings of shared_buffers on Windows similar
> to
>   Linux?
> 
> 
> 
> 
> Based on this optimization we might want to keep the text that says large
> shared buffers on Windows aren't as effective perhaps, and just remove the
> sentence that explicitly says don't go over 512MB?

Just removing the reference to the size would make users ask a question "What 
size is the effective upper limit?"

Regards
Takayuki Tsunakawa


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Do we need use more meaningful variables to replace 0 in catalog head files?

2016-11-10 Thread Jan de Visser

On 2016-11-09 10:47 AM, Tom Lane wrote:


Amit Langote  writes:

On Wed, Nov 9, 2016 at 11:47 PM, Tom Lane  wrote:

Hmm, that's from 2009.  I thought I remembered something much more recent,
like last year or so.

This perhaps:
* Re: Bootstrap DATA is a pita *
https://www.postgresql.org/message-id/flat/CAOjayEfKBL-_Q9m3Jsv6V-mK1q8h%3Dca5Hm0fecXGxZUhPDN9BA%40mail.gmail.com

Yeah, that's the thread I remembered.  I think the basic conclusion was
that we needed a Perl script that would suck up a bunch of data from some
representation that's more edit-friendly than the DATA lines, expand
symbolic representations (regprocedure etc) into numeric OIDs, and write
out the .bki script from that.  I thought some people had volunteered to
work on that, but we've seen no results ...

regards, tom lane




Would a python script converting something like json or yaml be 
acceptable? I think right now only perl is used, so it would be a new 
build chain tool, albeit one that's in my (very humble) opinion much 
better suited to the task.




--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Do we need use more meaningful variables to replace 0 in catalog head files?

2016-11-10 Thread Tom Lane
Corey Huinker  writes:
> On Wed, Nov 9, 2016 at 10:47 AM, Tom Lane  wrote:
>> Yeah, that's the thread I remembered.  I think the basic conclusion was
>> that we needed a Perl script that would suck up a bunch of data from some
>> representation that's more edit-friendly than the DATA lines, expand
>> symbolic representations (regprocedure etc) into numeric OIDs, and write
>> out the .bki script from that.  I thought some people had volunteered to
>> work on that, but we've seen no results ...

> If there are no barriers to adding it to our toolchain, could that
> more-edit-friendly representation be a SQLite database?

I think you've fundamentally missed the point here.  A data dump from a
table would be semantically indistinguishable from the lots-o-DATA-lines
representation we have now.  What we want is something that isn't that.
In particular I don't see how that would let us have any extra level of
abstraction that's not present in the finished form of the catalog tables.
(An example that's already there is FLOAT8PASSBYVAL for the value of
typbyval appropriate to float8 and allied types.)

I'm not very impressed with the suggestion of making a competing product
part of our build dependencies, either.  If we wanted to get into build
dependency circularities, we could consider using a PG database in this
way ... but I prefer to leave such headaches to compiler authors for whom
it comes with the territory.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread leoaaryan
Hi Jay,

If you are talking about
http://evol-monkey.blogspot.com/2013/08/setting-sharedbuffers-hard-way.html
and the "pg_buffercache" extensions then yes I have gone through it.

The easiest way to find the value for the shared memory computation is to
change the logging level to DEBUG3 and start postgres DB engine and it will
give the calculated value in the log file.

I believe postgres as a DB needs to be running for any extension to run (I
may be wrong here) and I dont want to start the database for this analysis. 

Please correct me if I'm wrong in my concepts or if I've not understood
anything.

-leoaaryan.



--
View this message in context: 
http://postgresql.nabble.com/Shared-memory-estimation-for-postgres-tp5929868p5929872.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Do we need use more meaningful variables to replace 0 in catalog head files?

2016-11-10 Thread Corey Huinker
On Wed, Nov 9, 2016 at 10:47 AM, Tom Lane  wrote:

> Yeah, that's the thread I remembered.  I think the basic conclusion was
> that we needed a Perl script that would suck up a bunch of data from some
> representation that's more edit-friendly than the DATA lines, expand
> symbolic representations (regprocedure etc) into numeric OIDs, and write
> out the .bki script from that.  I thought some people had volunteered to
> work on that, but we've seen no results ...
>

If there are no barriers to adding it to our toolchain, could that
more-edit-friendly representation be a SQLite database?

I'm not suggesting we store a .sqlite file in our repo. I'm suggesting that
we store the dump-restore script in our repo, and the program that
generates the .bki script would query the generated SQLite db.

>From that initial dump, any changes to pg_proc.h would be appended to the
dumped script

...

/* add new frombozulation feature */

ALTER TABLE pg_proc_template ADD frombozulator text;
/* bubbly frombozulation is the default for volatile functions */
UPDATE pg_proc_template SET frombozulator = 'bubbly' WHERE provolatile =
'v';

/* proposed new function */

INSERT INTO pg_proc_template(proname,proleakproof) VALUES ("new_func",'f');



That'd communicate the meaning of our changes rather nicely. A way to eat
our own conceptual dogfood.

Eventually it'd get cluttered and we'd replace the populate script with a
fresh ".dump". Maybe we do that as often as we reformat our C code.

I think Stephen Frost suggested something like this a while back, but I
couldn't find it after a short search.


Re: [HACKERS] Shared memory estimation for postgres

2016-11-10 Thread John Scalia
Do a web search on setting shared memory the hard way, and I think you'll see 
what you really need to do.
--
Jay

Sent from my iPad

> On Nov 10, 2016, at 5:57 PM, leoaaryan  wrote:
> 
> I am a newbie to databases and Postgres and I am trying to analyze the shared
> memory being calculated and allocated by Postgres in the method
> "CreateSharedMemoryAndSemaphores" for different major versions for different
> postgres.conf file
> 
> My idea was to create a utility in Postgres and calll out the methods like
> BufferShmemSize(), LockShmemSize() etc being used in the
> CreateSharedMemoryAndSemaphores() to find the value.
> 
> Till now what I have done: I have created a new utility and am trying to
> link the src/backend code to it but I'm not able to get it working
> correctly. 
> 
> Is there any other interest idea / way where I use a postgres.conf file to
> calculate the above mentioned shared memory value ? 
> 
> I have found this discussion thread from the past but haven't made much
> sense to me in terms of where to look.
> Old discussion thread:
> http://postgresql.nabble.com/postgresql-conf-basic-analysis-tool-td1948070.html
> 
> 
> 
> --
> View this message in context: 
> http://postgresql.nabble.com/Shared-memory-estimation-for-postgres-tp5929868.html
> Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.
> 
> 
> -- 
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Something is broken about connection startup

2016-11-10 Thread Tom Lane
I wrote:
> A quick look through the sources confirms that this error implies that
> SearchSysCache on the RELOID cache must have failed to find a tuple for
> pg_proc --- there are many occurrences of this text, but they all are
> reporting that.  Which absolutely should not be happening now that we use
> MVCC catalog scans, concurrent updates or no.  So I think this is a bug,
> and possibly a fairly-recently-introduced one, because I can't remember
> seeing buildfarm failures like this one before.

After tweaking elog.c to promote FATAL to PANIC, I got stack traces
confirming that the error occurs here:

#0  0x003779a325e5 in raise (sig=6) at 
../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x003779a33dc5 in abort () at abort.c:92
#2  0x0080d177 in errfinish (dummy=) at elog.c:560
#3  0x0080df94 in elog_finish (elevel=, 
fmt=) at elog.c:1381
#4  0x00801859 in RelationCacheInitializePhase3 () at relcache.c:3444
#5  0x0081a145 in InitPostgres (in_dbname=, 
dboid=0, 
username=, useroid=, 
out_dbname=0x0)
at postinit.c:982
#6  0x00710c81 in PostgresMain (argc=1, argv=, 
dbname=0x24d4c40 "regression", username=0x24abc88 "postgres") at 
postgres.c:3728
#7  0x006a6eae in BackendRun (argc=, 
argv=) at postmaster.c:4271
#8  BackendStartup (argc=, argv=)
at postmaster.c:3945
#9  ServerLoop (argc=, argv=)
at postmaster.c:1701
#10 PostmasterMain (argc=, argv=)
at postmaster.c:1309
#11 0x006273d8 in main (argc=3, argv=0x24a9b20) at main.c:228

So it's happening when RelationCacheInitializePhase3 is trying to replace
a fake pg_class row for pg_proc (made by formrdesc) with the real one.
That's even odder, because that's late enough that this should be a pretty
ordinary catalog lookup.  Now I wonder if it's possible that this can be
seen during ordinary relation opens after connection startup.  If so, it
would almost surely be a recently-introduced bug, else we'd have heard
about this from the field.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Shared memory estimation for postgres

2016-11-10 Thread leoaaryan
I am a newbie to databases and Postgres and I am trying to analyze the shared
memory being calculated and allocated by Postgres in the method
"CreateSharedMemoryAndSemaphores" for different major versions for different
postgres.conf file

My idea was to create a utility in Postgres and calll out the methods like
BufferShmemSize(), LockShmemSize() etc being used in the
CreateSharedMemoryAndSemaphores() to find the value.

Till now what I have done: I have created a new utility and am trying to
link the src/backend code to it but I'm not able to get it working
correctly. 

Is there any other interest idea / way where I use a postgres.conf file to
calculate the above mentioned shared memory value ? 

I have found this discussion thread from the past but haven't made much
sense to me in terms of where to look.
Old discussion thread:
http://postgresql.nabble.com/postgresql-conf-basic-analysis-tool-td1948070.html



--
View this message in context: 
http://postgresql.nabble.com/Shared-memory-estimation-for-postgres-tp5929868.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Something is broken about connection startup

2016-11-10 Thread Tom Lane
I noticed that buildfarm member piculet fell over this afternoon:
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=piculet=2016-11-10%2020%3A10%3A02
with this interesting failure during startup of the "collate" test:
psql: FATAL:  cache lookup failed for relation 1255

1255 is pg_proc, and nosing around, I noticed that the concurrent
"init_privs" test does this:
GRANT SELECT ON pg_proc TO CURRENT_USER;
GRANT SELECT (prosrc) ON pg_proc TO CURRENT_USER;

So that led me to hypothesize that GRANT on a system catalog can cause a
concurrent connection failure, which I tested by running

pgbench -U postgres -n -f script1.sql -T 300 regression
with this script:
GRANT SELECT ON pg_proc TO CURRENT_USER;
GRANT SELECT (prosrc) ON pg_proc TO CURRENT_USER;
REVOKE SELECT ON pg_proc FROM CURRENT_USER;
REVOKE SELECT (prosrc) ON pg_proc FROM CURRENT_USER;

and concurrently
pgbench -C -U postgres -n -f script2.sql -c 10 -j 10 -T 300 regression
with this script:
select 2 + 2;

and sure enough, the second one falls over after a bit with

connection to database "regression" failed:
FATAL:  cache lookup failed for relation 1255
client 5 aborted while establishing connection

For me, this typically happens within thirty seconds or less.  I thought
perhaps it only happened with --no-atomics which piculet is using, but
nope, I can reproduce it in a stock debug build.  For the record, I'm
testing on an 8-core x86_64 machine running RHEL6.

Note: you can't merge this test scenario into one pgbench run with two
scripts, because then you can't keep pgbench from sometimes running two
instances of script1 concurrently, with ensuing "tuple concurrently
updated" errors.  That's something we've previously deemed not worth
changing, and in any case it's not what I'm on about at the moment.
I tried to make script1 safe for concurrent calls by putting "begin; lock
table pg_proc in share row exclusive mode; ...; commit;" around it, but
that caused the error to go away, or at least become far less frequent.
Which is odd in itself, since that lock level shouldn't block connection
startup accesses to pg_proc.

A quick look through the sources confirms that this error implies that
SearchSysCache on the RELOID cache must have failed to find a tuple for
pg_proc --- there are many occurrences of this text, but they all are
reporting that.  Which absolutely should not be happening now that we use
MVCC catalog scans, concurrent updates or no.  So I think this is a bug,
and possibly a fairly-recently-introduced one, because I can't remember
seeing buildfarm failures like this one before.

I've not dug further than that yet.  Any thoughts out there?

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Logical Replication WIP

2016-11-10 Thread Petr Jelinek
On 04/11/16 13:15, Andres Freund wrote:
> 
>  /* Prototypes for private functions */
> -static bool libpq_select(int timeout_ms);
> +static bool libpq_select(PGconn *streamConn,
> +  int timeout_ms);
> 
> If we're starting to use this more widely, we really should just a latch
> instead of the plain select(). In fact, I think it's more or less a bug
> that we don't (select is only interruptible by signals on a subset of
> our platforms).  That shouldn't bother this patch, but...
> 
> 

Agree that this is problem, especially for the subscription creation
later. We should be doing WaitLatchOrSocket, but the question is which
latch. We can't use MyProc one as that's not the latch that WalReceiver
uses so I guess we would have to send latch as parameter to any caller
of this which is not very pretty from api perspective but I don't have
better idea here.

-- 
  Petr Jelinek  http://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] WAL consistency check facility

2016-11-10 Thread Michael Paquier
On Fri, Nov 11, 2016 at 1:36 AM, Robert Haas  wrote:
> So, who are all of the people involved in the effort to produce this
> patch, and what's the right way to attribute credit?

The original idea was from Heikki as he has introduced the idea of
doing such checks if you look at the original thread. I added on top
of it a couple of things like the concept of page masking, and hacked
an early version of the versoin we have now
(https://www.postgresql.org/message-id/cab7npqr4vxdkijp+du82vocongmvutq-gfqiu2dsh4bsm77...@mail.gmail.com).
So it seems to me that marking Heikki as an author would be fair as
the original idea is from him. I don't mind being marked only as a
reviewer of the feature, or as someone from which has written an
earlier version of the patch, but I let that up to your judgement.
Kuntai is definitely an author.
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Declarative partitioning - another take

2016-11-10 Thread Robert Haas
On Wed, Nov 9, 2016 at 9:58 PM, Amit Langote
 wrote:
>> With all patches applied, "make check" fails with a bunch of diffs
>> that look like this:
>>
>>   Check constraints:
>> - "pt1chk2" CHECK (c2 <> ''::text)
>>   "pt1chk3" CHECK (c2 <> ''::text)
>
> Hm, I can't seem to reproduce this one.  Is it perhaps possible that you
> applied the patches on top of some other WIP patches or something?

Nope.  I just checked and this passes with only 0001 and 0002 applied,
but when I add 0003 and 0004 then it starts failing.  It appears that
the problem starts at this point in the foreign_data test:

ALTER TABLE pt1 DROP CONSTRAINT pt1chk2 CASCADE;

After that command, in the expected output, pt1chk2 stops showing up
in the output of \d+ pt1, but continues to appear in the output of \d+
ft2.  With your patch, however, it stops showing up for ft2 also.  If
that's not also happening for you, it might be due to an uninitialized
variable someplace.

+/* Force inheritance recursion, if partitioned table. */

Doesn't match code (any more).

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Improvements in psql hooks for variables

2016-11-10 Thread Daniel Verite
Rahila Syed wrote:

> I have applied this patch on latest HEAD and have done basic testing which
> works fine.

Thanks for reviewing this patch!

> >if (current->assign_hook)
> >-   (*current->assign_hook) (current->value);
> >-   return true;
> >+   {
> >+   confirmed = (*current->assign_hook) (value);
> >+   }
> >+   if (confirmed)
> 
> Spurious brackets

OK.

> >static bool
> >+generic_boolean_hook(const char *newval, const char* varname, bool *flag)
> >+{
> 
> Contrary to what name suggests this function does not seem to have other
> implementations as in a hook.
> Also this takes care of rejecting a syntactically wrong value only for
> boolean variable hooks like autocommit_hook,
> on_error_stop_hook. However, there are other variable hooks which call
> ParseVariableBool.
> For instance, echo_hidden_hook which is handled separately in the patch.
> Thus there is some duplication of code between generic_boolean_hook and
> echo_hidden_hook.
> Similarly for on_error_rollback_hook.

The purpose of generic_boolean_hook() is to handle the case of a
boolean variable that only accepts ON or OFF, and has its pset.varname
declared as bool. I thought of this case as "generic" because that's
the base case and several variables need no more than that.

ECHO_HIDDEN differs from the generic boolean case because it also
accepts "noexec" and pset.echo_hidden is an enum, not a boolean. When
considering refactoring echo_hidden_hook() to call
generic_boolean_hook() instead of ParseVariableBool() after 
having established that the value is not "noexec", I don't see
any advantage in clarity or code size, so I'm not in favor of that change.

The same applies to on_error_rollback_hook(), which has to deal
with a specific enum as well.

> >-static void
> >+static bool
> > fetch_count_hook(const char *newval)
> > {
> >pset.fetch_count = ParseVariableNum(newval, -1, -1, false);
> >+   return true;
> > }
> 
> Shouldn't invalid numeric string assignment for numeric variables be
> handled too?

Agreed. Assignments like "\set FETCH_COUNT bogus" don't provoke any
user feedback currently, which is not ideal. I'll add this in a
v3 of the patch tomorrow.

> Instead of generic_boolean_hook cant we have something like follows which
> like generic_boolean_hook can be called from specific variable assignment
> hooks,
> 
> static bool
> ParseVariable(newval, VariableName, )
> {
> if (VariableName == ‘AUTOCOMMIT’ || ECHO_HIDDEN || other variable with
> hooks which call ParseVariableBool )
>   ON_ERROR_ROLLBACK>
> else if (VariableName == ‘FETCH_COUNT’)
> ParseVariableNum();
> }

It's not possible because pset.var corresponds to different fields from
struct _psqlSettings that have different types: bool, int and some
enum types.
Besides, I don't think it would go well with hooks. If we wanted one
big function that knows all about parsing all built-in variables, we
could just as well dispense with hooks, since their current purpose in
psql is to achieve this parsing, but in a decentralized way.
Or if we keep them, our various built-in variables would be
essentially tied to the same one-big-hook-that-does-all, but isn't
that an antipattern for hooks?


> >@@ -260,7 +276,7 @@ SetVariableAssignHook(VariableSpace space, const char
> *name, VariableAssignHook
> >current->assign_hook = hook;
> >current->next = NULL;
> >previous->next = current;
> >-   (*hook) (NULL);
> >+   (void)(*hook) (NULL);   /* ignore return value */
> 
> Sorry for my lack of understanding, can you explain why is above change
> needed?

"hook" is changed by the patch from [pointer to function returning
void], to [pointer to function returning bool]. The cast to void is
not essential, it just indicates that we deliberately want to
ignore the return value here. I expect some compilers might
complain under a high level of warnings without this cast, although
TBH if you ask me, I wouldn't know which compiler with which flags
exactly.


Best regards,
-- 
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] checkpoint_flush_after and friends

2016-11-10 Thread Jeff Janes
On Thu, Nov 10, 2016 at 12:17 PM, Andres Freund  wrote:

> On 2016-11-10 12:13:05 -0800, Jeff Janes wrote:
> > configuration parameters *_flush_after were added in 9.6.  They are not
> in
> > postgresql.conf.sample, but are also not marked GUC_NOT_IN_SAMPLE.  Is
> this
> > intentional and/or desirable?
>
> Hm?
>
> $ grep flush_after src/backend/utils/misc/postgresql.conf.sample
> #bgwriter_flush_after = 0   # 0 disables,
> #backend_flush_after = 0# 0 disables, default is 0
> #wal_writer_flush_after = 1MB   # 0 disables
> #checkpoint_flush_after = 0 # 0 disables,
>
> Andres
>

My apologies.  I must have gotten my default conf file from the wrong
initdb.

Jeff


Re: [HACKERS] checkpoint_flush_after and friends

2016-11-10 Thread Andres Freund
On 2016-11-10 12:13:05 -0800, Jeff Janes wrote:
> configuration parameters *_flush_after were added in 9.6.  They are not in
> postgresql.conf.sample, but are also not marked GUC_NOT_IN_SAMPLE.  Is this
> intentional and/or desirable?

Hm?

$ grep flush_after src/backend/utils/misc/postgresql.conf.sample
#bgwriter_flush_after = 0   # 0 disables,
#backend_flush_after = 0# 0 disables, default is 0
#wal_writer_flush_after = 1MB   # 0 disables
#checkpoint_flush_after = 0 # 0 disables,

Andres


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] checkpoint_flush_after and friends

2016-11-10 Thread Jeff Janes
configuration parameters *_flush_after were added in 9.6.  They are not in
postgresql.conf.sample, but are also not marked GUC_NOT_IN_SAMPLE.  Is this
intentional and/or desirable?

Cheers,

Jeff


Re: [HACKERS] WIP: About CMake v2

2016-11-10 Thread Tom Lane
Mark Kirkwood  writes:
> I would recommend making it behave as Tom suggested. *Then* add an 
> --autodetect or similar option that makes
> behave in the 'finding and using what it could' manner as a 2nd patch.

An "--autodetect" switch would be fine with me.  I just don't want it
to behave that way by default, because then you get into the unexpected
results problem.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] WIP: About CMake v2

2016-11-10 Thread Mark Kirkwood

On 11/11/16 08:15, Yury Zhuravlev wrote:


Craig Ringer wrote:

So personally I think it'd be fine if a cmake build defaulted to
finding and using what it could, but offered a --minimal mode or
whatever that gets us just core postgres + whatever we enable
explicitly. But our current behaviour is OK too.


To me it's best way. But I'm not sure what Tom Lane will accept this.




I just had a play with this patch - nice! (ok so it needs a fix so that 
the compile completes as mentioned prev).


I would recommend making it behave as Tom suggested. *Then* add an 
--autodetect or similar option that makes

behave in the 'finding and using what it could' manner as a 2nd patch.

regards

Mark


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] WIP: About CMake v2

2016-11-10 Thread Yury Zhuravlev

Craig Ringer wrote:

So personally I think it'd be fine if a cmake build defaulted to
finding and using what it could, but offered a --minimal mode or
whatever that gets us just core postgres + whatever we enable
explicitly. But our current behaviour is OK too.


To me it's best way. But I'm not sure what Tom Lane will accept this.


--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: [BUGS] BUG #14350: VIEW with INSTEAD OF INSERT TRIGGER and COPY. Missing feature or working as designed.

2016-11-10 Thread Tom Lane
Haribabu Kommi  writes:
> [ copy_to_view_3.patch ]

Pushed with cosmetic adjustments.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Improving RLS planning

2016-11-10 Thread Dean Rasheed
On 10 November 2016 at 17:12, Tom Lane  wrote:
> Yeah, I think we'd be best off to avoid the bare term "security".
> It's probably too late to change the RTE field name "securityQuals",
> but maybe we could uniformly call those "security barrier quals" in
> the comments.  Then the basic terminology is that we have security
> barrier views and row-level security both implemented on top of
> security barrier quals, and we should be careful to use the right
> one of those three terms in comments/documentation.
>

+1 for that terminology and no renaming of fields.

Regards,
Dean


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Declarative partitioning - another take

2016-11-10 Thread Robert Haas
On Thu, Nov 10, 2016 at 7:40 AM, Amit Langote
 wrote:
>> I think "partitioning key" is a bit awkward and actually prefer
>> "partiton key".  But "partition method" sounds funny so I would go
>> with "partitioning method".
>
> OK, "partition key" and "partitioning method" it is then.  Source code
> comments, error messages, variables call the latter (partitioning)
> "strategy" though which hopefully is fine.

Oh, I like "partitioning strategy".  Can we standardize on that?

>>> Related to range partitioning, should we finalize on inclusive START/FROM
>>> and exclusive END/TO preventing explicit specification of the inclusivity?
>>
>> I would be in favor of committing the initial patch set without that,
>> and then considering the possibility of adding it later.  If we
>> include it in the initial patch set we are stuck with it.
>
> OK, I have removed the syntactic ability to specify INCLUSIVE/EXCLUSIVE
> with each of the range bounds.
>
> I haven't changed any code (such as comparison functions) that manipulates
> instances of PartitionRangeBound which has a flag called inclusive.  I
> didn't remove the flag, but is instead just set to (is_lower ? true :
> false) when initializing from the parse node. Perhaps, there is some scope
> for further simplifying that code, which you probably alluded to when you
> proposed that we do this.

Yes, you need to rip out all of the logic that supports it.  Having
the logic to support it but not the syntax is bad because then that
code can't be properly tested.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] proposal: psql \setfileref

2016-11-10 Thread Pavel Stehule
2016-11-10 18:56 GMT+01:00 Tom Lane :

> Pavel Stehule  writes:
> > 2016-11-09 22:47 GMT+01:00 Tom Lane :
> >> * I really dislike the notion of keying the behavior to a special type
> of
> >> psql variable.
>
> > still I am thinking so some differencing can be nice, because we can use
> > psql file path tab autocomplete.
> > Maybe \setfileref can stay - it will set any variable, but the
> autocomplete
> > will be based on file path.
>
> Personally, I'd rather have filename tab completion after ":<", and forget
> \setfileref --- I do not think that setting a variable first is going to
> be the primary use-case for this.  In fact, I could happily dispense with
> the variable case entirely, except that sometimes people will want to
> reference file names that don't syntactically fit into the colon syntax
> (eg, names with spaces in them).  Even that seems surmountable, if people
> are okay with requiring the '<' trailer --- I don't think we need to worry
> too much about supporting file names with '<' in them.  (Likewise for
> '>', if you feel like : is a less ugly syntax.)
>

In this case I dislike '>' on the end. The semantic is less clear with it.

I though about dropping variables too, but I expecting a expandable
variable after colon syntax. So it need special clear syntax for disabling
variable expansion.

What about :<{filename} ?

INSERT INTO tab VALUES(1, :<{~/data/doc.txt});



>
> > What do you thing about following example?
>
> > INSERT INTO tab VALUES(1, : > escaping
> > INSERT INTO tab VALUES(1, :<#varname); -- insert bytea value  -- used
> bytea
> > escaping
>
> Seems a bit arbitrary, and not readily extensible to more datatypes.
>

there are only two possibilities - text with client encoding to server
encoding conversions, and binary - without any conversions.


>
> I guess an advantage of the parameterized-query approach is that we
> wouldn't really have to distinguish different datatypes in the syntax,
> because we could use the result of Describe Statement to figure out what
> to do.  Maybe that outweighs the concern about magic behavioral changes.
>

I don't understand - there is a possibility to detect type of parameter on
client side?


>
> On the other hand, it's also arguable that trying to cater for automatic
> handling of raw files as bytea literals is overcomplicating the feature
> in support of a very infrequent use-case, and giving up some other
> infrequent use-cases to get that.  An example is that if we insist on
> doing this through parameterized queries, it will not work for inserting
> literals into utility commands.  I don't know which of these things is
> more important to have.
>

I had not idea a complete replacement of current mechanism by query
parameters. But a partial usage can be source of inconsistencies :(

Pavel



>
> regards, tom lane
>


Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread David Steele
On 11/10/16 1:03 PM, Stephen Frost wrote:
> On Thursday, November 10, 2016, Joshua D. Drake  > wrote:
> 
> On 11/10/2016 09:33 AM, David Steele wrote:
> 
> On 11/10/16 10:28 AM, Stephen Frost wrote:
> 
> diff --git a/src/backend/access/transam/xlog.c
> b/src/backend/access/transam/xlog.c
> 
> [...]
> 
> +   if (log_checkpoints)
> +   ereport(LOG,
> (errmsg("checkpoint skipped")));
> 
> 
> Do we really need to log that we're skipping a
> checkpoint..?  As the
> point of this is to avoid write activity on a system which
> is idle, it
> doesn't make sense to me to add a new cause for writes to
> happen when
> we're idle.
> 
> 
> log_checkpoints is not enabled by default, though, so if the
> user does
> enable it don't you think they would want to know when checkpoints
> *don't* happen?
> 
> 
> Yes but I don't know that it needs to be anywhere below DEBUG2 (vs
> log_checkpoints).
> 
> 
> Agreed. You certainly may wish to log checkpoints, even on an embedded
> or low I/o system, but logging that nothing is happening doesn't seem
> useful except perhaps for debugging. 

Sure, DEBUG1 or DEBUG2 makes sense.

-- 
-David
da...@pgmasters.net


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread Stephen Frost
On Thursday, November 10, 2016, Joshua D. Drake 
wrote:

> On 11/10/2016 09:33 AM, David Steele wrote:
>
>> On 11/10/16 10:28 AM, Stephen Frost wrote:
>>
>> diff --git a/src/backend/access/transam/xlog.c
 b/src/backend/access/transam/xlog.c

>>> [...]
>>>
 +   if (log_checkpoints)
 +   ereport(LOG, (errmsg("checkpoint
 skipped")));

>>>
>>> Do we really need to log that we're skipping a checkpoint..?  As the
>>> point of this is to avoid write activity on a system which is idle, it
>>> doesn't make sense to me to add a new cause for writes to happen when
>>> we're idle.
>>>
>>
>> log_checkpoints is not enabled by default, though, so if the user does
>> enable it don't you think they would want to know when checkpoints
>> *don't* happen?
>>
>
> Yes but I don't know that it needs to be anywhere below DEBUG2 (vs
> log_checkpoints).
>

Agreed. You certainly may wish to log checkpoints, even on an embedded or
low I/o system, but logging that nothing is happening doesn't seem useful
except perhaps for debugging.

Thanks!

Stephen


Re: [HACKERS] proposal: psql \setfileref

2016-11-10 Thread Tom Lane
Pavel Stehule  writes:
> 2016-11-09 22:47 GMT+01:00 Tom Lane :
>> * I really dislike the notion of keying the behavior to a special type of
>> psql variable.

> still I am thinking so some differencing can be nice, because we can use
> psql file path tab autocomplete.
> Maybe \setfileref can stay - it will set any variable, but the autocomplete
> will be based on file path.

Personally, I'd rather have filename tab completion after ":<", and forget
\setfileref --- I do not think that setting a variable first is going to
be the primary use-case for this.  In fact, I could happily dispense with
the variable case entirely, except that sometimes people will want to
reference file names that don't syntactically fit into the colon syntax
(eg, names with spaces in them).  Even that seems surmountable, if people
are okay with requiring the '<' trailer --- I don't think we need to worry
too much about supporting file names with '<' in them.  (Likewise for
'>', if you feel like : is a less ugly syntax.)

> What do you thing about following example?

> INSERT INTO tab VALUES(1, : escaping
> INSERT INTO tab VALUES(1, :<#varname); -- insert bytea value  -- used bytea
> escaping

Seems a bit arbitrary, and not readily extensible to more datatypes.

I guess an advantage of the parameterized-query approach is that we
wouldn't really have to distinguish different datatypes in the syntax,
because we could use the result of Describe Statement to figure out what
to do.  Maybe that outweighs the concern about magic behavioral changes.

On the other hand, it's also arguable that trying to cater for automatic
handling of raw files as bytea literals is overcomplicating the feature
in support of a very infrequent use-case, and giving up some other
infrequent use-cases to get that.  An example is that if we insist on
doing this through parameterized queries, it will not work for inserting
literals into utility commands.  I don't know which of these things is
more important to have.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH] Reload SSL certificates on SIGHUP

2016-11-10 Thread Andreas Karlsson

On 11/10/2016 07:16 AM, Michael Paquier wrote:

On Wed, Nov 9, 2016 at 7:46 PM, Andreas Karlsson  wrote:

Those tests fail due to that listen_addresses cannot be changed on reload so
none of the test cases can even connect to the database. When I hacked
ServerSetup.pm to set the correct listen_address before starting all tests
pass.


Hm... listen_addresses remain constant at 127.0.0.1 and setting up
listen_addresses = '*' does not work either.. Perhaps I am missing
something?


When PostgreSQL is started in the tests it by default only listens to a 
unix socket (except on Windows). It is the call to the restart function 
in the SSL tests which allows PostgreSQL to receive TCP connections.


Fixing this in the SSL tests will require some refactoring.


It is a bit annoying that if pg_hba.conf contains hostssl then postgres will
refuse to start. Maybe this is something we should also fix in this patch
since now when we can enable SSL after starting it becomes more useful to
not bail on hostssl. What do you think?


I forgot that... There is the same problem today when updating
postgresql.conf and restarting the server if there is an hostssl
entry. Do you have in mind to relax things? It seems to be that the
safest bet is to not reload parameters if ssl is switched from on to
off and if pg_hba.conf has a hostssl entry, right? That complicates
the code though.


I personally think that it would be cleaner and easier to understand if 
we just do not fail on hostssl lines just because SSL is disabled. A 
warning should be enough. But I do not have any strong opinions here, 
and would be fine with leaving the code as-is.



I will look into writing a cleaner patch for ServerSetup.pm some time later
this week.


Thanks. Making the restart/reload OS-dependent will be necessary.
src/test/ssl can run on Windows.


I do not think that this will be an issue with the current design, but I 
do not have access to a Windows machine for testing.


Andreas


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread Joshua D. Drake

On 11/10/2016 09:33 AM, David Steele wrote:

On 11/10/16 10:28 AM, Stephen Frost wrote:


diff --git a/src/backend/access/transam/xlog.c 
b/src/backend/access/transam/xlog.c

[...]

+   if (log_checkpoints)
+   ereport(LOG, (errmsg("checkpoint skipped")));


Do we really need to log that we're skipping a checkpoint..?  As the
point of this is to avoid write activity on a system which is idle, it
doesn't make sense to me to add a new cause for writes to happen when
we're idle.


log_checkpoints is not enabled by default, though, so if the user does
enable it don't you think they would want to know when checkpoints
*don't* happen?


Yes but I don't know that it needs to be anywhere below DEBUG2 (vs 
log_checkpoints).


Sincerely,

JD



--
Command Prompt, Inc.  http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread David Steele
On 11/10/16 10:28 AM, Stephen Frost wrote:

>> diff --git a/src/backend/access/transam/xlog.c 
>> b/src/backend/access/transam/xlog.c
> [...]
>> +if (log_checkpoints)
>> +ereport(LOG, (errmsg("checkpoint skipped")));
> 
> Do we really need to log that we're skipping a checkpoint..?  As the
> point of this is to avoid write activity on a system which is idle, it
> doesn't make sense to me to add a new cause for writes to happen when
> we're idle.

log_checkpoints is not enabled by default, though, so if the user does
enable it don't you think they would want to know when checkpoints
*don't* happen?

Or are you thinking the main use of this logging is to determine when
checkpoints are too close together and so skipped checkpoints aren't
very important?

Thanks,
-- 
-David
da...@pgmasters.net



signature.asc
Description: OpenPGP digital signature


Re: [HACKERS] Improving RLS planning

2016-11-10 Thread Tom Lane
Stephen Frost  writes:
> * Dean Rasheed (dean.a.rash...@gmail.com) wrote:
>> On 8 November 2016 at 14:45, Tom Lane  wrote:
>>> ... I'm still suspicious that the three places I found may
>>> represent bugs in the management of Query.hasRowSecurity.

>> I don't believe that there are any existing bugs here, but I think 1
>> or possibly 2 of the 3 places you changed should be kept on robustness
>> grounds (see below).

> Agreed.

OK.  I'll push a small patch that adds two of those and a comment as to
why it's not appropriate in the third case.  HEAD-only should be
sufficient since we don't think this is a live bug.

>> On a related note, I think it's worth establishing a terminology
>> convention for code and comments in this whole area.

> For my 2c, 'security' is a pretty overloaded term, unfortunately.

Yeah, I think we'd be best off to avoid the bare term "security".
It's probably too late to change the RTE field name "securityQuals",
but maybe we could uniformly call those "security barrier quals" in
the comments.  Then the basic terminology is that we have security
barrier views and row-level security both implemented on top of
security barrier quals, and we should be careful to use the right
one of those three terms in comments/documentation.

Or, if you are willing to put up with renaming the field, we could
call the RTE field "barrierQuals" and then they are just "barrier
quals" for documentation purposes.  But this would be a PITA for
back-patching, so I'm not sure it's worth it.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] WAL consistency check facility

2016-11-10 Thread Robert Haas
On Thu, Nov 10, 2016 at 10:02 AM, Kuntal Ghosh
 wrote:
>> With the patch for BRIN applied, I am able to get installcheck-world
>> working with wal_consistency = all and a standby doing the consistency
>> checks behind. Adding wal_consistency = all in PostgresNode.pm, the
>> recovery tests are passing. This patch is switched as "Ready for
>> Committer". Thanks for completing this effort begun 3 years ago!
> Thanks to you for reviewing all the patches in so much detail. Amit, Robert
> and Dilip also helped me a lot in developing the feature. Thanks to them
> as well.

So, who should be credited as co-authors of this patch and in what
order, if and when it gets committed?  If X started this patch and
then Kuntal did a little more work on it, I would credit it as:

X and Kuntal Ghosh

If Kuntal did major work on it, though, then I would think of
something more like:

Kuntal Ghosh, based on an earlier patch from X

If he didn't use any of the old code but just the idea, then I would
do something like this:

Kuntal Ghosh, inspired by a previous patch from X

So, who are all of the people involved in the effort to produce this
patch, and what's the right way to attribute credit?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Fix checkpoint skip logic on idle systems by tracking LSN progress

2016-11-10 Thread Stephen Frost
Michael,

* Michael Paquier (michael.paqu...@gmail.com) wrote:
> Thanks for the review! Waiting for a couple of days more is fine for
> me. This won't change much. Attached is v15 with the fixes you
> mentioned.

I figured I'd go ahead and start looking into this (and it's pretty easy
for me to discuss it with David, given he works in the same office ;).

A couple initial comments:

> diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
> index adab2f8..38c2385 100644
> --- a/doc/src/sgml/config.sgml
> +++ b/doc/src/sgml/config.sgml
> @@ -2826,12 +2826,9 @@ include_dir 'conf.d'
>  parameter is greater than zero, the server will switch to a new
>  segment file whenever this many seconds have elapsed since the last
>  segment file switch, and there has been any database activity,
> -including a single checkpoint.  (Increasing
> -checkpoint_timeout will reduce unnecessary
> -checkpoints on an idle system.)
> -Note that archived files that are closed early
> -due to a forced switch are still the same length as completely full
> -files.  Therefore, it is unwise to use a very short
> +including a single checkpoint.  Note that archived files that are
> +closed early due to a forced switch are still the same length as
> +completely full files.  Therefore, it is unwise to use a very short
>  archive_timeout  it will bloat your archive
>  storage.  archive_timeout settings of a minute or so are
>  usually reasonable.  You should consider using streaming replication,

We should probably include in here that we may skip a checkpoint if no
activity has happened, meaning that this is a safe setting to set for
environments which are idle for long periods (I'm thinking embedded
systems here).

> diff --git a/src/backend/access/transam/xlog.c 
> b/src/backend/access/transam/xlog.c
[...]
> + if (log_checkpoints)
> + ereport(LOG, (errmsg("checkpoint skipped")));

Do we really need to log that we're skipping a checkpoint..?  As the
point of this is to avoid write activity on a system which is idle, it
doesn't make sense to me to add a new cause for writes to happen when
we're idle.

Thanks!

Stephen


signature.asc
Description: Digital signature


Re: [HACKERS] WAL consistency check facility

2016-11-10 Thread Kuntal Ghosh
On Thu, Nov 10, 2016 at 10:25 AM, Michael Paquier
 wrote:
> On Wed, Nov 9, 2016 at 11:32 PM, Kuntal Ghosh
>> Thanks a lot for reviewing the patch. Based on your review, I've attached the

>> I've done a fair amount of testing which includes regression tests
>> and manual creation of inconsistencies in the page. I've also found the
>> reason behind inconsistency in brin revmap page.
>> Brin revmap page doesn't have standard page layout. Besides, It doesn't 
>> update
>> pd_upper and pd_lower in its operations as well. But, during WAL
>> insertions, it uses
>> REGBUF_STANDARD to register a reference in the WAL record. Hence, when we
>> restore image before consistency check, RestoreBlockImage fills the space
>> between pd_upper and pd_lower(page hole) with zero. I've posted this as a
>> separate thread.
>> https://www.postgresql.org/message-id/flat/CAGz5QCJ%3D00UQjScSEFbV%3D0qO5ShTZB9WWz_Fm7%2BWd83zPs9Geg%40mail.gmail.com#CAGz5QCJ=00UQjScSEFbV=0qo5shtzb9wwz_fm7+wd83zps9...@mail.gmail.com
>
> Nice to have spotted the inconsistency. This tool is going to be useful..
>
> I have spent a couple of hours playing with the patch, and worked on
> it a bit more with a couple of minor changes:
> - In gindesc.c, the if blocks are more readable with brackets.
> - Addition of a comment when info is set, to mention that this is done
> at the beginning of the routine so as callers of XLogInsert() can pass
> the flag for consistency checks.
> - apply_image should be reset in ResetDecoder().
> - The BRIN problem is here:
> 2016-11-10 12:24:10 JST [65776]: [23-1] db=,user=,app=,client= FATAL:
> Inconsistent page found, rel 1663/16385/30625, forknum 0, blkno 1
> 2016-11-10 12:24:10 JST [65776]: [24-1] db=,user=,app=,client=
> CONTEXT:  xlog redo at 0/9BD31148 for BRIN/UPDATE+INIT: heapBlk 100
> pagesPerRange 1 old offnum 11, new offnum 1
> 2016-11-10 12:24:10 JST [65776]: [25-1] db=,user=,app=,client=
> WARNING:  buffer refcount leak: [4540] (rel=base/16385/30625,
> blockNum=1, flags=0x9380, refcount=1 1)
> TRAP: FailedAssertion("!(RefCountErrors == 0)", File: "bufmgr.c", Line: 2506)
> Now the buffer refcount leak is not normal! The safest thing to do
> here is to release the buffer once a copy of it has been taken, and
> the leaks goes away when calling FATAL to report the inconsistency.
> - When checking for XLR_CHECK_CONSISTENCY, better to add a != 0 to get
> a boolean out of it.
> - guc_malloc() should be done as late as possible, this simplifies the
> code and prevents any memory leaks which is what your patch is doing
> when there is an error. (I have finally put my finger on what was
> itching me here).
> - In btree_mask, the lookup of BTP_DELETED can be deadly simplified.
> - I wondered also about putting assign_wal_consistency and
> check_wal_consistency in a separate file, say xlogparams.c, concluding
> that the current code does nothing bad either even if it adds rmgr.h
> in the list of headers in guc.c.
> - Some comment blocks are longer than 72~80 characters.
> - Typos!
All the changes make perfect sense to me.

> With the patch for BRIN applied, I am able to get installcheck-world
> working with wal_consistency = all and a standby doing the consistency
> checks behind. Adding wal_consistency = all in PostgresNode.pm, the
> recovery tests are passing. This patch is switched as "Ready for
> Committer". Thanks for completing this effort begun 3 years ago!
Thanks to you for reviewing all the patches in so much detail. Amit, Robert
and Dilip also helped me a lot in developing the feature. Thanks to them
as well.


-- 
Thanks & Regards,
Kuntal Ghosh
EnterpriseDB: http://www.enterprisedb.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Patch: Implement failover on libpq connect level.

2016-11-10 Thread Mithun Cy
On Thu, Nov 10, 2016 at 1:11 PM, Tsunakawa, Takayuki <
tsunakawa.ta...@jp.fujitsu.com> wrote:
> Why don't you add "standby" and "prefer_standby" as the
target_server_type value?  Are you thinking that those values are useful
with load balancing > feature?
Yes this patch will only address failover to new master, values "master"
and "any" appeared sufficient for that case.

-- 
Thanks and Regards
Mithun C Y
EnterpriseDB: http://www.enterprisedb.com


Re: [HACKERS] Copying Permissions

2016-11-10 Thread Stephen Frost
Corey,

* Corey Huinker (corey.huin...@gmail.com) wrote:
> I think allowing users to receive and send serialized relacl values (which
> is what I *think* you're asking about here) is only slightly less icky, and

That isn't actually what I was suggesting.

> presents a backward compatibility issue. Those issues go away if the ACL is
> contained in an existing object, or exists only for the life of a
> statement. In which case I think you're suggesting something like this:

Right- an existing 'object'.

What I was suggesting is that we have, for lack of a better word,
'profiles'- which are essentially complete, named, aclitem arrays.  That
way, we aren't tying this to an existing object in the system but rather
making it a top-level object on its own, in a manner akin to how the
default privileges system contains acitem arrays which are not
associated with an object.

Consider:

CREATE PROFILE joe_select GRANT SELECT ON TABLES TO joe;
ALTER DEFAULT PRIVILEGES IN SCHEMA joes PROFILE joe_select;
ALTER TABLE joe SET PROFILE joe_select;

etc.

The other question this brings up, as I think I mentioned before, is
this: is this a one-time copy of that 'profile'?  What if the profile
is later changed?

For my 2c, I kind of like the idea that an update to the profile would
cause the privileges to be effectivly changed for all objects using that
profile, though that may mean we end up with a different kind of
implementation than what you proposed of just copying the relacl.

Generally speaking, setting a profile should be the purview of the owner
of the object, imv.  We would also have to consider if objects can have
both a profile and independently granted accesses.  I'm thinking the
answer to that is probably 'yes'.

Thanks!

Stephen


signature.asc
Description: Digital signature


Re: [HACKERS] Bug in comparison of empty jsonb arrays to scalars

2016-11-10 Thread Tom Lane
Michael Paquier  writes:
> On Thu, Nov 10, 2016 at 7:37 AM, Tom Lane  wrote:
>> Given that nobody actually cares what that sort order is, I think that
>> having to jump through hoops in pg_upgrade in order to fix it is not a
>> great tradeoff.  I suggest changing the documentation to match the code.

> Yes, definitely.
> So that's object > boolean > integer > string > NULL > array.

No, because the issue is that empty and nonempty arrays sort differently.

regression=# create table json_data (a jsonb);
CREATE TABLE
regression=#  INSERT INTO json_data values ('{}'::jsonb), ('[]'::jsonb),
regression-# ('null'::jsonb), ('true'::jsonb), ('1'::jsonb), ('""'::jsonb),
regression-# ('[42]'::jsonb),('[[43]]'::jsonb);
INSERT 0 8
regression=# SELECT * FROM json_data ORDER BY 1 DESC;
   a

 {}
 [[43]]
 [42]
 true
 1
 ""
 null
 []
(8 rows)

> And attached is a patch.

If we go with the fix-the-docs approach, we'll need to have two entries
for empty and nonempty arrays.  It's definitely ugly.  Still, my judgement
is that it's not worth the pain of changing the behavior.  It was never
intended that this sort order be anything but an implementation detail.

(I guess another approach is to not document the order at all ...)

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] proposal: psql \setfileref

2016-11-10 Thread Pavel Stehule
Hi

2016-11-09 22:47 GMT+01:00 Tom Lane :

> Pavel Stehule  writes:
> > [ psql-setfileref-2016-10-11.patch ]
>
> I haven't been paying any attention to this thread, but I got around to
> looking at it finally.  I follow the idea of wanting to be able to shove
> the contents of a file into a query literal, but there isn't much else
> that I like about this patch.  In particular:
>
> * I really dislike the notion of keying the behavior to a special type of
> psql variable.  psql variables are untyped at the moment, and if we were
> going to introduce typing, this wouldn't be what I'd want to use it for.
> I really don't want to introduce typing and then invent one-off,
> unextensible syntax like '^' prefixes to denote what type a variable is.
>

still I am thinking so some differencing can be nice, because we can use
psql file path tab autocomplete.

Maybe \setfileref can stay - it will set any variable, but the autocomplete
will be based on file path.


>
> Aside from being conceptually a mess, I don't even find it particularly
> convenient.  In the shell, if you want to source from a file, you write
> " and then write "<$filename" ... although you can if that's actually
> helpful.
>
> Going by the notion of driving it off syntax not variable type, I'd
> suggest that we extend the colon-variablename syntax to indicate
> desire to read a file.  : Maybe we could use :<:variablename< to indicate substituting the
> content of a variable as the file name to read.
>

I used the concept of file references because I would not to invent new
syntax of psql variables evaluation.

If we introduce new syntax, then the variables are not necessary. The
syntax :some op has sense, and be used and enhanced in future.

What do you thing about following example?

INSERT INTO tab VALUES(1, :
> * I'm a bit queasy about the idea of automatically switching over to
> parameterized queries when we have one of these things in the query.
> I'm afraid that that will have user-visible consequences, so I would
> rather that psql not do that behind the user's back.  Plus, that assumes
> a fact not in evidence, namely that you only ever want to insert data
> and not code this way.  (If \i were more flexible, that objection would
> be moot, but you can't source just part of a query from \i AFAIK.)
> There might be something to be said for a psql setting that controls
> whether to handle colon-insertions this way, and make it apply to
> the existing :'var' syntax as well as the filename syntax.
>

I understand to this objection - The my motivation for parametrized queries
was better (user friendly) reaction on syntax errors. In this case  the
content can be big, the query can be big. When we use parametrized queries,
then the error message can be short and readable. Another advantage of
parametrized queries is possibility to set parameter type. It is important
for binary content. And last advantage is a possibility to use binary
passing - it is interesting for XML - it allows automatic encoding
conversions. These features are nice, but are not necessary for this patch.


>
> * I find the subthread about attaching this to COPY to be pretty much of
> a red herring.  What would that do that you can't do today with \copy?
>

The primary task is simple - import big XML, JSON document or  some binary
data to database. This can be partially solved by ref variables, but COPY
has more verbose and more natural syntax - the file path autocomplete can
be used.

\COPY table(column) FROM file FLAG;

Second task is not too complex too - export binary data from Postgres and
store these data in binary files. Now I have to use final transformation on
client side.

Third task - one interesting feature of XML type (automatic encoding
conversion) is available only with binary input output functions. I would
to find a way how this functionality can be accessed without "hard"
programming.

\COPY (SELECT xmldoc FROM xxx WHERE id = 111) TO file BINARY ENCODING
latin1;



Regards

Pavel



> regards, tom lane
>


Re: [HACKERS] Copying Permissions

2016-11-10 Thread Stephen Frost
Robert,

* Robert Haas (robertmh...@gmail.com) wrote:
> On Wed, Nov 9, 2016 at 2:54 PM, Corey Huinker  wrote:
> > 3. The operation is judged to have succeeded if at least one permission is
> > granted, or NO grants failed (i.e. there was nothing to grant).
> 
> Allow me to be skeptical.  If a user types INSERT INTO blah VALUES
> (...), (...), (...) should we change the system to report success if
> at least 1 of the 3 rows got successfully inserted?  I bet that
> wouldn't go over well.

To this point, we already do this for GRANT and REVOKE, so if this is
going to be based around those commands then it should perform in a
similar manner.  Of course, that behavior is required for SQL spec and
as Tom points out that might be reason enough to avoid actually tying
this in with GRANT/REVOKE since we could end up in a tough spot if the
SQL committee decides to take a different direction than what we use (or
use the keywords we pick for something else).

Thanks!

Stephen


signature.asc
Description: Digital signature


Re: [HACKERS] Is user_catalog_table sensible for matviews?

2016-11-10 Thread Tom Lane
Andres Freund  writes:
> On 2016-11-09 12:55:51 -0500, Robert Haas wrote:
>> On Wed, Nov 9, 2016 at 12:17 PM, Tom Lane  wrote:
>>> The system will let you set the "user_catalog_table" reloption to "true"
>>> on a materialized view.  Is this sensible, or is it a bug caused by the
>>> fact that reloptions.c fails to distinguish matviews from heaps at all?
>>> If it is sensible, then I broke it in e3e66d8a9 ...

>> I can understand what that combination of opens would mean from a
>> semantic point of view, so I don't think it's insensible.  However, it
>> doesn't seem like an important combination to support, and I suspect
>> that the fact that we did was accidental.

> I don't see it as being important either. I suspect we intentionally
> didn't exclude it, but less because of a use-case and more because there
> didn't seem to be a need to.

I think it's fundamentally wrong that reloptions.c doesn't distinguish
matviews from heaps.  You can argue about whether this particular case
is okay or not, but sooner or later there's going to be an option that
only applies to one of them.  So I plan to invent RELOPT_KIND_MATVIEW
while I'm rejiggering things to fix the rd_options type safety issue.

Having done that, we could either allow this for matviews or not.
I'm agnostic.  However, unless we feel like back-patching some
modification of e3e66d8a9, 9.5.x and 9.6.x are effectively not
going to allow it (they'd take the option but then ignore it).
I guess that's arguably a bug in itself.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Improving RLS planning

2016-11-10 Thread Stephen Frost
Dean,

* Dean Rasheed (dean.a.rash...@gmail.com) wrote:
> On 8 November 2016 at 14:45, Tom Lane  wrote:
> > OK.  In that case I'll need to adjust the patch so that the planner keeps
> > its own flag about whether the query contains any securityQuals; that's
> > easy enough.  But I'm still suspicious that the three places I found may
> > represent bugs in the management of Query.hasRowSecurity.
> 
> I don't believe that there are any existing bugs here, but I think 1
> or possibly 2 of the 3 places you changed should be kept on robustness
> grounds (see below).

Agreed.

> On a related note, I think it's worth establishing a terminology
> convention for code and comments in this whole area. In the existing
> code, or in my head at least, there's a convention that a term that
> contains the words "row" or "policy" together with "security" refers
> specifically to RLS, not to SB views. For example:

Agreed, at least for 'row security'.  I tend to view 'policy' as just
about sufficient to stand on its own, in an 'object' type of context
(vs. something like a 'policy decision').  There aren't many other
mentions of policy in src/backend either, the notable one I found
quickly being 'LockWaitPolicy'.  That strikes me as pretty distinctive
from RLS-related policies though.

> * Row-level security or just row security for the name of the feature itself
> * row_security -- the configuration setting
> * get_row_security_policies()
> * Query.hasRowSecurity
> * rowsecurity.c
> 
> On the other hand, terms that contain just the word "security" without
> the words "row" or "policy" have a broader scope and may refer to
> either RLS or SB views. For example:

For my 2c, 'security' is a pretty overloaded term, unfortunately.  We
also have things like fmgr_security_definer(), fmgr_info_cxt_security(),
the security label system, etc, so I don't know that 'security' can
really stand on its own, except perhaps within a specific context, like
"within the rewriter and planner/optimizer, 'security' generally is
going to be talking about security barriers, be they for RLS or security
barrier views."  Even that is likely a bit of a stretch though.  I tend
think we should move in more of a 'Security Barrier'/'SecBarrier' or
similar direction.  Anyone working with the code associated with this
should understand that RLS is built on top of the security barrier
system.

I'm not sure we need to get particularly wrapped up in this, however, or
go making changes just for the sake of making them.

> It's a pretty fine distinction, and I don't know how others have been
> thinking about this, but I think that it's helpful to make the
> distinction, and there are at least a couple of places in the patch
> that use RLS-specific terminology for what could also be a SB view.

I agree that we shouldn't be using RLS-specific terminology for
components which are actually used by RLS and SB views.

Thanks!

Stephen


signature.asc
Description: Digital signature


Re: [HACKERS] Unlogged tables cleanup

2016-11-10 Thread Kuntal Ghosh
On Thu, Nov 10, 2016 at 3:42 PM, Michael Paquier
 wrote:
> On Thu, Nov 10, 2016 at 5:15 PM, Michael Paquier
>  wrote:
>> Okay, so what happens is that the CREATE TABLESPACE record removes the
>> tablespace directory and recreates a fresh one, but as no CREATE
>> records are created for unlogged tables the init fork is not
>> re-created. It seems to me that we should log a record to recreate the
>> INIT fork, and that heap_create_with_catalog() is missing something.
>> Generating a record in RelationCreateStorage() is the more direct way,
>> and that actually fixes the issue. Now the comments at the top of it
>> mention that RelationCreateStorage() should only be used to create the
>> MAIN forknum. So, wouldn't a correct fix be to log this INIT record at
>> the end of heap_create()?
>
> Nah. Looking at the code the fix is quite obvious.
> heap_create_init_fork() is checking for XLogIsNeeded() to decide if
> the INIT forknum should be logged or not. But this is wrong, it needs
> to be done unconditionally to ensure that the relation gets created at
> replay.
I think that we should also update other *buildempty() functions as well.
For example, if the table has a primary key, we'll encounter the error again
for btree index.


-- 
Thanks & Regards,
Kuntal Ghosh
EnterpriseDB: http://www.enterprisedb.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] switching documentation build to XSLT

2016-11-10 Thread Peter Eisentraut
Some work has been going on recently to be able to update our
documentation build tool chain.  After discussion on pgsql-docs, the
people involved agree that it is time to move forward.

We are now proposing that we change the way the HTML documentation is
built from jade/openjade+docbook-dsssl to xsltproc+docbook-xsl.

If you can build the man pages now (make man, also included in make
world), then you don't need any new tools.  The new HTML build will be
using the same tools.  Otherwise, follow the documentation to set up
those tools and make that work.

The actual patch to make this change is attached.  For the build
process, nothing changes, e.g., 'make' or 'make html' will still have
the same purposes.

For the time being, you will still be able to build the documentation
the old way with 'make oldhtml', but this is mainly so that we can
compare the output and work out any formatting kinks.  Before this
patch, you can also build the documentation the new way using 'make
xslthtml', but that will go away.

I will submit a separate patch to the web site team to update the CSS
style sheets for the web site to match the new output.

There are more steps to be done after this, to move over the other
output formats (PDF), adjust the configure script, the documentation,
work out any remaining formatting problems, etc., so now is a good time
to get this rolling so that we have a good chance of reaching a steady
state before the end of the development cycle.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From e2e142b69e3e299932219bb5659f1bef2c78f26a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut 
Date: Tue, 8 Nov 2016 12:00:00 -0500
Subject: [PATCH] Build HTML documentation using XSLT stylesheets by default

The old DSSSL build is still available for a while using the make target
"oldhtml".
---
 doc/src/sgml/Makefile   |  8 
 doc/src/sgml/stylesheet.css | 50 +
 2 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/doc/src/sgml/Makefile b/doc/src/sgml/Makefile
index 84c94e8..fe7ca65 100644
--- a/doc/src/sgml/Makefile
+++ b/doc/src/sgml/Makefile
@@ -106,9 +106,9 @@ draft: postgres.sgml $(ALMOSTALLSGML) stylesheet.dsl
 	$(JADE.html.call) -V draft-mode $<
 	cp $(srcdir)/stylesheet.css html/
 
-html: html-stamp
+oldhtml: oldhtml-stamp
 
-html-stamp: postgres.sgml $(ALLSGML) stylesheet.dsl
+oldhtml-stamp: postgres.sgml $(ALLSGML) stylesheet.dsl
 	$(MAKE) check-tabs
 	$(MKDIR_P) html
 	$(JADE.html.call) -i include-index $<
@@ -258,9 +258,9 @@ ifeq ($(STYLE),website)
 XSLTPROC_HTML_FLAGS += --param website.stylesheet 1
 endif
 
-xslthtml: xslthtml-stamp
+html: html-stamp
 
-xslthtml-stamp: stylesheet.xsl postgres.xml
+html-stamp: stylesheet.xsl postgres.xml
 	$(XMLLINT) --noout --valid postgres.xml
 	$(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $^
 	cp $(srcdir)/stylesheet.css html/
diff --git a/doc/src/sgml/stylesheet.css b/doc/src/sgml/stylesheet.css
index 60dcc76..f845876 100644
--- a/doc/src/sgml/stylesheet.css
+++ b/doc/src/sgml/stylesheet.css
@@ -2,18 +2,18 @@
 
 /* color scheme similar to www.postgresql.org */
 
-BODY {
+body {
 	color: #00;
 	background: #FF;
 	font-family: verdana, sans-serif;
 }
 
-A:link		{ color:#0066A2; }
-A:visited	{ color:#004E66; }
-A:active	{ color:#0066A2; }
-A:hover		{ color:#00; }
+a:link		{ color:#0066A2; }
+a:visited	{ color:#004E66; }
+a:active	{ color:#0066A2; }
+a:hover		{ color:#00; }
 
-H1 {
+h1 {
 	font-size: 1.4em;
 	font-weight: bold;
 	margin-top: 0em;
@@ -21,34 +21,34 @@ H1 {
 	color: #EC5800;
 }
 
-H2 {
+h2 {
 	font-size: 1.2em;
 	margin: 1.2em 0em 1.2em 0em;
 	font-weight: bold;
-	color: #666;
+	color: #EC5800;
 }
 
-H3 {
+h3 {
 	font-size: 1.1em;
 	margin: 1.2em 0em 1.2em 0em;
 	font-weight: bold;
 	color: #666;
 }
 
-H4 {
+h4 {
 	font-size: 0.95em;
 	margin: 1.2em 0em 1.2em 0em;
 	font-weight: normal;
 	color: #666;
 }
 
-H5 {
+h5 {
 	font-size: 0.9em;
 	margin: 1.2em 0em 1.2em 0em;
 	font-weight: normal;
 }
 
-H6 {
+h6 {
 	font-size: 0.85em;
 	margin: 1.2em 0em 1.2em 0em;
 	font-weight: normal;
@@ -56,13 +56,13 @@ H6 {
 
 /* center some titles */
 
-.BOOK .TITLE, .BOOK .CORPAUTHOR, .BOOK .COPYRIGHT {
+.book .title, .book .corpauthor, .book .copyright {
 	text-align: center;
 }
 
 /* decoration for formal examples */
 
-DIV.EXAMPLE {
+div.example {
 	padding-left: 15px;
 	border-style: solid;
 	border-width: 0px;
@@ -71,28 +71,16 @@ DIV.EXAMPLE {
 	margin: 0.5ex;
 }
 
-/* less dense spacing of TOC */
-
-.BOOK .TOC DL DT {
-	padding-top: 1.5ex;
-	padding-bottom: 1.5ex;
-}
-
-.BOOK .TOC DL DL DT {
-	padding-top: 0ex;
-	padding-bottom: 0ex;
-}
-
 /* miscellaneous */
 
-PRE.LITERALLAYOUT, .SCREEN, .SYNOPSIS, .PROGRAMLISTING {
+pre.literallayout, .screen, .synopsis, .programlisting {
 	margin-left: 4ex;
 }
 
-.COMMENT	{ color: red; }
+.comment	{ color: red; }
 
-VAR		{ 

Re: [HACKERS] Bug in comparison of empty jsonb arrays to scalars

2016-11-10 Thread Nikita Glukhov

On 10.11.2016 09:54, Michael Paquier wrote:


Yes, definitely.
=# create table json_data (a jsonb);
CREATE TABLE
=# INSERT INTO json_data values ('{}'::jsonb), ('[]'::jsonb),
('null'::jsonb), ('true'::jsonb), ('1'::jsonb), ('""'::jsonb);
INSERT 0 6
=# SELECT * FROM json_data ORDER BY 1 DESC;
   a
--
  {}
  true
  1
  ""
  null
  []
(6 rows)
So that's object > boolean > integer > string > NULL > array.

And attached is a patch.


Perhaps I did not explain it clearly enough, but only *empty top-level* 
arrays are out of the correct order.

See complete example:

=# SELECT * FROM (VALUES
('null'::jsonb), ('0'), ('""'), ('true'), ('[]'), ('{}'),
('[null]'), ('[0]'), ('[""]'), ('[true]'), ('[[]]'), ('[{}]'),
('{"a": null}'), ('{"a": 0}'), ('{"a": ""}'), ('{"a": true}'), 
('{"a": []}'), ('{"a": {}}')

) valsORDER BY 1;
   column1
-
 []
 null
 ""
 0
 true
 [null]
 [""]
 [0]
 [true]
 [[]]
 [{}]
 {}
 {"a": null}
 {"a": ""}
 {"a": 0}
 {"a": true}
 {"a": []}
 {"a": {}}
(18 rows)


--
Nikita Glukhov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Fwd: Re: [CORE] temporal tables (SQL2011)

2016-11-10 Thread Stefan Scheid
Hi,
thanks for elaborating.

yes, of course, I can implement 
it with 3 triggers, adding a couple of columns. It doesn't affect design and 
testing which stay the same.
As we are developing a product that must support a couple of databases and as I 
am not really happy with Maria e.a.,
I want to switch our standard DBMS. We need to support ms and ora as well, so 
there are h2, db2 and pg, or maybe we switch to some nonrel stuff like neo.
A couple of years ago I migrated a cms from db2 to pg, and was quite 
impressed... thats my current "mind map" :-)

Von meinem iPhone gesendet

> Am 10.11.2016 um 01:26 schrieb Craig Ringer :
> 
> On 8 Nov. 2016 15:11, "Craig Ringer"  wrote:
> >
> >
> >
> > On 7 November 2016 at 05:08, Stefan Scheid  wrote:
> >>
> >> Hi all,
> >>
> >> are there plans to introduce temporal tables?
> >
> > I don't know of anybody working on them, but someone else may. Try 
> > searching the list archives.
> 
> I should've mentioned that one of the reasons it doesn't seem to be that high 
> on many people's priority lists is that it's fairly easy to implement with 
> triggers and updatable views. There's a greater performance cost than I'd 
> expect to pay for the same thing done as a built-in feature, but it works 
> well enough.
> 
> Many ORMs and application frameworks also offer similar capabilities at the 
> application level.
> 
> So I think temporal tables are one of those nice-to-haves that so far people 
> just find other ways of doing.


Re: [HACKERS] Adding in docs the meaning of pg_stat_replication.sync_state

2016-11-10 Thread Fujii Masao
On Wed, Nov 9, 2016 at 2:33 PM, Michael Paquier
 wrote:
> Hi all,
>
> The documentation does not explain at all what means "sync" or "async"
> on pg_stat_replication.

"potential" state also should be explained?

> The paragraph "Planning for high availability"
> mentions "catchup" and "streaming", but it does not say that users can
> refer to it directly in pg_stat_replication.
>
> Thoughts about the patch attached to add a couple of sentences in
> "Planning for high availability"? We could as well mention it directly
> in the page of pg_stat_replication but this information seems more
> suited if located in the HA section.

Yeah, I think it's better to mention them even in pg_stat_replication page.

Regards,

-- 
Fujii Masao


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Floating point comparison inconsistencies of the geometric types

2016-11-10 Thread Emre Hasegeli
> Returning to the issue, the following query should give you the
> expected result.
>
> SELECT name, #thepath  FROM iexit ORDER BY name COLLATE "C", 2;

Yes, I have worked around it like this.  What I couldn't understand is
how my patch can cause this regression.  How is it passes on master
without COLLATE?


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Improving RLS planning

2016-11-10 Thread Dean Rasheed
On 8 November 2016 at 16:46, Robert Haas  wrote:
> On Thu, Nov 3, 2016 at 6:23 PM, Tom Lane  wrote:
>>> I think that ordering might be sub-optimal if you had a mix of
>>> leakproof quals and security quals and the cost of some security quals
>>> were significantly higher than the cost of some other quals. Perhaps
>>> all leakproof quals should be assigned security_level 0, to allow them
>>> to be checked earlier if they have a lower cost (whether or not they
>>> are security quals), and only leaky quals would have a security_level
>>> greater than zero. Rule 1 would then not need to check whether the
>>> qual was leakproof, and you probably wouldn't need the separate
>>> "leakproof" bool field on RestrictInfo.
>>
>> Hm, but it would also force leakproof quals to be evaluated in front
>> of potentially-cheaper leaky quals, whether or not that's semantically
>> necessary.
>>

True. That's also what currently happens with RLS and SB views because
leakproof quals are pushed down into subqueries without considering
their cost. It would be nice to do better than that.


>> I experimented with ignoring security_level altogether for leakproof
>> quals, but I couldn't make it work properly, because that didn't lead to
>> a comparison rule that satisfies transitivity.  For instance, consider
>> three quals:
>> A: cost 1, security_level 1, leaky
>> B: cost 2, security_level 1, leakproof
>> C: cost 3, security_level 0, leakproof
>> A should sort before B, since same security_level and lower cost;
>> B should sort before C, since lower cost and leakproof;
>> but A must sort after C, since higher security_level and leaky.
>
> Yeah, this is pretty thorny.  IIUC, all leaky quals of a given
> security level must be evaluated before any quals of the next higher
> security level, or we have a security problem.  Beyond that, we'd
> *prefer* to evaluate cheaper quals first (though perhaps we ought to
> be also thinking about how selective they are) but that's "just" a
> matter of how good the query plan is.  So in this example, security
> dictates that C must precede A, but that's it.  We can pick between
> C-A-B, C-B-A, and B-C-A based on cost.  C-B-A is clearly inferior to
> either of the other two, but it's less obvious whether C-A-B or B-C-A
> is better.  If you expect each predicate to have a selectivity of 50%,
> then C-A-B costs 3+(0.5*1)+(0.25*2) = 4 while B-C-A costs
> 2+(0.5*3)+(0.25*1) = 3.75, so B-C-A is better.  But now make the cost
> of B and C 18 and 20 while keeping the cost of A at 1.  Now C-A-B
> costs 20+(0.5*1)+(0.25*18) = 25 while B-C-A costs 18+(0.5*20)+(0.25*1)
> = 28.25, so now C-A-B is better.
>
> So I think any attempt to come up with a transitive comparison rule is
> doomed.  We could do something like: sort by cost then security level;
> afterwards, allow leakproof qual to migrate forward as many position
> as is possible without passing a qual that is either higher-cost or
> (non-leakproof and lower security level).  So in the above example we
> would start by sorting the like C-A-B and then check whether B can
> move forward; it can't, so we're done.  If all operators were
> leakproof, this would essentially turn into an insertion-sort that
> orders them strictly by cost, whereas if they're all leaky, it orders
> strictly by security level and then by cost.  With a mix of leaky and
> non-leaky operators you get something in the middle.
>
> I'm not sure that this is practically better than the hack you
> proposed, but I wanted to take the time to comment on the theory here,
> as I see it anyway.
>

Yes, I think you're right. It doesn't look possible to invent a
transitive comparison rule.

I thought perhaps the rule could be to only "push down" a leakproof
qual (change it to a lower security_level) if there are more expensive
quals at the lower level, but as you point out, this doesn't guarantee
cheaper execution.

Regards,
Dean


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Improving RLS planning

2016-11-10 Thread Dean Rasheed
On 8 November 2016 at 14:45, Tom Lane  wrote:
> Stephen Frost  writes:
>> * Tom Lane (t...@sss.pgh.pa.us) wrote:
>>> * Since the planner is now depending on Query.hasRowSecurity to be set
>>> whenever there are any securityQuals, I put in an Assert about that,
>>> and promptly found three places in prepjointree.c and the rewriter where
>>> we'd been failing to set it.  I have not looked to see if these represent
>>> live bugs in existing releases, but they might.  Or am I misunderstanding
>>> what the flag is supposed to mean?
>
>> They're independent, actually.  securityQuals can be set via either
>> security barrier view or from RLS, while hasRowSecurity is specifically
>> for the RLS case.  The reason for the distinction is that changing your
>> role isn't going to impact security barrier views at all, while it could
>> impact what RLS policies are used.  See extract_query_dependencies().
>

Right. securityQuals was added for updatable SB views, which pre-dates RLS.


> OK.  In that case I'll need to adjust the patch so that the planner keeps
> its own flag about whether the query contains any securityQuals; that's
> easy enough.  But I'm still suspicious that the three places I found may
> represent bugs in the management of Query.hasRowSecurity.
>

I don't believe that there are any existing bugs here, but I think 1
or possibly 2 of the 3 places you changed should be kept on robustness
grounds (see below).

Query.hasRowSecurity is only used for invalidation of cached plans,
when the current role or environment changes, causing a change to the
set of policies that need to be applied, and thus requiring that the
query be re-planned. This happens in extract_query_dependencies(),
which walks the query tree and will find any Query.hasRowSecurity
flags and set PlannerGlobal.dependsOnRole, which is sufficient for its
intended purpose.

Regarding the 3 places you mention...

1). rewriteRuleAction() doesn't need to set Query.hasRowSecurity
because it's called during "Step 1" of the rewriter, where non-SELECT
rules are expanded, but RLS expansion doesn't happen until later, at
the end of "Step 2", after SELECT rules are expanded. That said, you
could argue that copying the flag in rewriteRuleAction() makes the
code more bulletproof, even though it is expected to always be false
at that point.

2). pull_up_simple_subquery() technically doesn't need to set
Query.hasRowSecurity because nothing in the planner refers to it, and
plancache.c will have already recorded the fact that the original
query had RLS. However, this seems like a bug waiting to happen, and
this really ought to be copying the flag in case we later add code
that does look at the flag later in the planning process.

3). rewriteTargetView() should not set the flag because the flag is
only for RLS, not for SB views, and we don't want cached plans for SB
views to be invalidated.


On a related note, I think it's worth establishing a terminology
convention for code and comments in this whole area. In the existing
code, or in my head at least, there's a convention that a term that
contains the words "row" or "policy" together with "security" refers
specifically to RLS, not to SB views. For example:

* Row-level security or just row security for the name of the feature itself
* row_security -- the configuration setting
* get_row_security_policies()
* Query.hasRowSecurity
* rowsecurity.c

On the other hand, terms that contain just the word "security" without
the words "row" or "policy" have a broader scope and may refer to
either RLS or SB views. For example:

* RangeTblEntry.security_barrier
* RangeTblEntry.securityQuals
* expand_security_quals()
* prepsecurity.c
* The new security_level field

It's a pretty fine distinction, and I don't know how others have been
thinking about this, but I think that it's helpful to make the
distinction, and there are at least a couple of places in the patch
that use RLS-specific terminology for what could also be a SB view.

Regards,
Dean


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Is user_catalog_table sensible for matviews?

2016-11-10 Thread Andres Freund
On 2016-11-09 12:55:51 -0500, Robert Haas wrote:
> On Wed, Nov 9, 2016 at 12:17 PM, Tom Lane  wrote:
> > The system will let you set the "user_catalog_table" reloption to "true"
> > on a materialized view.  Is this sensible, or is it a bug caused by the
> > fact that reloptions.c fails to distinguish matviews from heaps at all?
> >
> > If it is sensible, then I broke it in e3e66d8a9 ...
> 
> I can understand what that combination of opens would mean from a
> semantic point of view, so I don't think it's insensible.  However, it
> doesn't seem like an important combination to support, and I suspect
> that the fact that we did was accidental.

I don't see it as being important either. I suspect we intentionally
didn't exclude it, but less because of a use-case and more because there
didn't seem to be a need to.

Andres


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Floating point comparison inconsistencies of the geometric types

2016-11-10 Thread Kyotaro HORIGUCHI
Hello,

At Thu, 29 Sep 2016 10:37:30 +0200, Emre Hasegeli  wrote in 

> > regression=# select 'I- 580Ramp' < 'I- 580/I-680
> >   Ramp';
> >  ?column?
> > --
> >  t
> > (1 row)
> 
> on the Linux server I am testing, it is not:
> 
> > regression=# select 'I- 580Ramp' < 'I- 580/I-680
> >   Ramp';
> >  ?column?
> > --
> >  f
> > (1 row)
> 
> The later should be the case on your environment as the test was also
> failing for you.  This is not consistent with the expected test
> result.  Do you know how this test can still pass on the master?

Perhaps you ran the test under the environment LC_COLLATE (or
LANG) of something other than C. The reson for the result is
collation. The following returns expected result.


=# select 'I- 580Ramp' < ('I- 580/I-680 
 Ramp' COLLATE "C");
 ?column? 
--
 t
(1 row)

For a reason I don't know, say, en_US locale behaves in an
unintuitive way.

regression=# select ' ' < ('/' COLLATE "en_US"), ' x' < ('/a' COLLATE "en_US");
 ?column? | ?column? 
--+--
 t| f
(1 row)


Returning to the issue, the following query should give you the
expected result.

SELECT name, #thepath  FROM iexit ORDER BY name COLLATE "C", 2;

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Unlogged tables cleanup

2016-11-10 Thread Michael Paquier
On Thu, Nov 10, 2016 at 5:15 PM, Michael Paquier
 wrote:
> Okay, so what happens is that the CREATE TABLESPACE record removes the
> tablespace directory and recreates a fresh one, but as no CREATE
> records are created for unlogged tables the init fork is not
> re-created. It seems to me that we should log a record to recreate the
> INIT fork, and that heap_create_with_catalog() is missing something.
> Generating a record in RelationCreateStorage() is the more direct way,
> and that actually fixes the issue. Now the comments at the top of it
> mention that RelationCreateStorage() should only be used to create the
> MAIN forknum. So, wouldn't a correct fix be to log this INIT record at
> the end of heap_create()?

Nah. Looking at the code the fix is quite obvious.
heap_create_init_fork() is checking for XLogIsNeeded() to decide if
the INIT forknum should be logged or not. But this is wrong, it needs
to be done unconditionally to ensure that the relation gets created at
replay.
-- 
Michael
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 0cf7b9e..2497a1e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1380,8 +1380,7 @@ heap_create_init_fork(Relation rel)
 {
RelationOpenSmgr(rel);
smgrcreate(rel->rd_smgr, INIT_FORKNUM, false);
-   if (XLogIsNeeded())
-   log_smgrcreate(>rd_smgr->smgr_rnode.node, INIT_FORKNUM);
+   log_smgrcreate(>rd_smgr->smgr_rnode.node, INIT_FORKNUM);
smgrimmedsync(rel->rd_smgr, INIT_FORKNUM);
 }
 

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Remove the comment on the countereffectiveness of large shared_buffers on Windows

2016-11-10 Thread Magnus Hagander
On Tue, Nov 8, 2016 at 5:03 AM, Amit Kapila  wrote:

> On Tue, Nov 8, 2016 at 5:12 AM, Jeff Janes  wrote:
> > On Mon, Nov 7, 2016 at 5:55 AM, Amit Kapila 
> wrote:
> >>
> >> On Tue, Sep 20, 2016 at 8:15 AM, Tsunakawa, Takayuki
> >>  wrote:
> >> > I ran read-only and read-write modes of pgbench, and could not see any
> >> > apparent decrease in performance when I increased shared_buffers.  The
> >> > scaling factor is 200, where the database size is roughly 3GB.  I ran
> the
> >> > benchmark on my Windows 10 PC with 6 CPU cores and 16GB of RAM.  The
> >> > database and WAL is stored on the same HDD.
> >> >
> >> > <>
> >> > @echo off
> >> > for %%s in (256MB 512MB 1GB 2GB 4GB) do (
> >> >   pg_ctl -w -o "-c shared_buffers=%%s" start
> >> >   pgbench -c18 -j6 -T60 -S bench >> g:\b.txt 2>&1
> >> >   pg_ctl -t 3600 stop
> >> > )
> >> >
> >> > <>
> >> > shared_buffers  tps
> >> > 256MB  63056
> >> > 512MB  63918
> >> > 1GB  65520
> >> > 2GB  66840
> >> > 4GB  68270
> >> >
> >> > <>
> >> > shared_buffers  tps
> >> > 256MB  1138
> >> > 512MB  1187
> >> > 1GB  1571
> >> > 2GB  1650
> >> > 4GB  1598
> >> >
> >>
> >> Isn't it somewhat strange that writes are showing big win whereas
> >> reads doesn't show much win?
> >
> >
> > I don't find that unusual, and have seen the same thing on Linux.
> >
> > With small shared_buffers, you are constantly throwing dirty buffers at
> the
> > kernel in no particular order, and the kernel does a poor job of
> predicting
> > when the same buffer will be dirtied repeatedly and only needs the final
> > version of the data actually written to disk.
> >
>
> Okay and I think partially it might be because we don't have writeback
> optimization (done in 9.6) for Windows.  However, still the broader
> question stands that whether above data is sufficient to say that we
> can recommend the settings of shared_buffers on Windows similar to
> Linux?
>
>
Based on this optimization we might want to keep the text that says large
shared buffers on Windows aren't as effective perhaps, and just remove the
sentence that explicitly says don't go over 512MB?

-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/


Re: [HACKERS] Unlogged tables cleanup

2016-11-10 Thread Michael Paquier
On Thu, Nov 10, 2016 at 4:33 PM, Michael Paquier
 wrote:
> On Thu, Nov 10, 2016 at 4:23 PM, konstantin knizhnik
>  wrote:
>> No, it is latest sources from Postgres repository.
>> Please notice that you should create new database and tablespace to 
>> reproduce this issue.
>> So actually the whole sequence is
>>
>> mkdir fs
>> initdb -D pgsql
>> pg_ctl -D pgsql -l logfile start
>> psql postgres
>> # create tablespace fs location '/home/knizhnik/dtm-data/fs';
>> # set default_tablespace=fs;
>> # create unlogged table foo(x integer);
>> # insert into foo values(generate_series(1,10));
>> # ^D
>> pkill -9 postgres
>> pg_ctl -D pgsql -l logfile start
>> # select * from foo;
>
> OK, I understood what I was missing. This can be reproduced with
> wal_level = minimal. When using hot_standby things are working
> properly.

Okay, so what happens is that the CREATE TABLESPACE record removes the
tablespace directory and recreates a fresh one, but as no CREATE
records are created for unlogged tables the init fork is not
re-created. It seems to me that we should log a record to recreate the
INIT fork, and that heap_create_with_catalog() is missing something.
Generating a record in RelationCreateStorage() is the more direct way,
and that actually fixes the issue. Now the comments at the top of it
mention that RelationCreateStorage() should only be used to create the
MAIN forknum. So, wouldn't a correct fix be to log this INIT record at
the end of heap_create()?
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers