Re: Re: Generic Plans for Prepared Statement are 158155 times slower than Custom Plans

2019-05-08 Thread Deepak Somaiya
Sameer,were you able to resolve it? 

I am not sure if this is very common in postges  - I doubt though but have not 
seen such a drastic performance degradation and that too when planner making 
the call.  

Deepak


   On Tuesday, April 30, 2019, 1:27:14 AM PDT, Naik, Sameer 
 wrote:  
 
 >The problem seems to be that the actual values being used for
>c400129200 and c400127400 are quite common in the dataset, so that when 
>considering

>Filter: ... (c400129200 = '0'::citext) AND (c400127400 = 'DATASET1M'::citext)

>the planner makes a roughly correct assessment that there are a lot of such 
>rows, so it prefers to index on the basis of the giant OR clause instead, even 
>though that's fairly expensive.  But, when considering the generic case

>      ->  Index Scan using i776_0_400129200_t776 on t776  (cost=0.42..12.66 
>rows=1 width=52) (actual time=1190.399..5544.385 rows=48 loops=1)
>            Index Cond: ((c400129200 = $1) AND (c400127400 = $2))

> it's evidently guessing that just a few rows will match the index condition 
> (no more than about 3 given the cost number), making this plan look much 
> cheaper, so it goes with this plan.  I wonder what the actual distribution of 
> those keys is.

Distribution of the keys c400129200 and c400127400 .

The distribution of c400129200 is as follows- 
In entire table having 110743 records, there are 55370 records for which the 
value of c400129200 is 0. For each of the remaining 55,373 records the value of 
c400129200 is distinct.


The distribution of c400127400 is as follows- 
In entire table having 110743 records, there are 55370 records for which the 
value of c400127400 is  'DATASET1M' . For remaining 55,373 records the value of 
c400127400 the value is same and is ' 'DATASET2M'  .


-Thanks and Regards,
Sameer Naik

-Original Message-
From: Tom Lane [mailto:[email protected]] 
Sent: Monday, April 29, 2019 8:06 PM
To: Bruce Momjian 
Cc: Naik, Sameer ; [email protected]
Subject: [EXTERNAL] Re: Generic> Plans for Prepared Statement are 158155 times 
slower than Custom Plans

Bruce Momjian  writes:
> On Mon, Apr 29, 2019 at 10:36:20AM +, Naik, Sameer wrote:
>> Since Postgres 9.2, for prepared statements, the CBO automatically 
>> switches from Custom Plan to Generic plan on the sixth iteration 
>> (reference backend/ utils/cache/plancache.c).

> This is not totally true.

Yeah, that's a pretty inaccurate statement of the behavior.

The problem seems to be that the actual values being used for
c400129200 and c400127400 are quite common in the dataset, so that when 
considering

Filter: ... (c400129200 = '0'::citext) AND (c400127400 = 'DATASET1M'::citext)

the planner makes a roughly correct assessment that there are a lot of such 
rows, so it prefers to index on the basis of the giant OR clause instead, even 
though that's fairly expensive.  But, when considering the generic case

      ->  Index Scan using i776_0_400129200_t776 on t776  (cost=0.42..12.66 
rows=1 width=52) (actual time=1190.399..5544.385 rows=48 loops=1)
            Index Cond: ((c400129200 = $1) AND (c400127400 = $2))

it's evidently guessing that just a few rows will match the index condition (no 
more than about 3 given the cost number), making this plan look much cheaper, 
so it goes with this plan.  I wonder what the actual distribution of those keys 
is.


In v10 and later, it's quite possible that creating extended stats on the 
combination of those two columns would produce a better estimate.  Won't help 
OP on 9.6, though.

This isn't the first time we've seen a plan-choice failure of this sort.
I've wondered if we should make the plancache simply disbelieve generic cost 
estimates that are actually cheaper than the custom plans, on the grounds that 
they must be estimation errors.  In principle a generic plan could never really 
be better than a custom plan; so if it looks that way on a cost basis, what 
that probably means is that the actual parameter values are outliers of some 
sort (e.g. extremely common), and the custom plan "knows" that it's going to be 
taking a hit from that, but the generic plan doesn't.  In this sort of 
situation, going with the generic plan could be really disastrous, which is 
exactly what the OP is seeing (and what we've seen reported before).

However, I'm not sure how to tune this idea so that it doesn't end up rejecting 
perfectly good generic plans.  It's likely that there will be some variation in 
the cost estimates between the generic and specific cases, even if the plan 
structure is exactly the same; and that variation could go in either direction.

            regards, tom lane

  

integrate Postgres Users Authentication with our own LDAP Server

2019-05-08 Thread M Tarkeshwar Rao
Hi all,

We would need to integrate Postgres Users Authentication with our own LDAP 
Server.

Basically as of now we are able to login to Postgress DB with a user/password 
credential.
[cid:[email protected]]

These user objects are the part of Postgres DB server. Now we want that these 
users should be authenticated by LDAP server.
We would want the authentication to be done with LDAP, so basically the user 
credentials should be store in LDAP server

Can you mention the prescribed steps in Postgres needed for this integration 
with LDAP Server?

Regards
Tarkeshwar


Re: integrate Postgres Users Authentication with our own LDAP Server

2019-05-08 Thread Laurenz Albe
On Thu, 2019-05-09 at 04:51 +, M Tarkeshwar Rao wrote:
> We would need to integrate Postgres Users Authentication with our own LDAP 
> Server.  
>  
> Basically as of now we are able to login to Postgress DB with a user/password 
> credential.
>
> [roles "pg_signal_backend" and "postgres"]
>  
> These user objects are the part of Postgres DB server. Now we want that these 
> users should be authenticated by LDAP server.
> We would want the authentication to be done with LDAP, so basically the user 
> credentials should be store in LDAP server
>  
> Can you mention the prescribed steps in Postgres needed for this integration 
> with LDAP Server?

LDAP authentication is well documented:
https://www.postgresql.org/docs/current/auth-ldap.html

But I don't think you are on the right track.

"pg_signal_backend" cannot login, it is a role to which you add a login user
to give it certain privileges.  So you don't need to authenticate the role.

"postgres" is the installation superuser.  If security is important for you,
you won't set a password for that user and you won't allow remote logins
with that user.

But for your application users LDAP authentication is a fine thing, and not
hard to set up if you know a little bit about LDAP.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com