Thread: Postgres DB crashing

Postgres DB crashing

From
bhanu udaya
Date:
Hello,
Greetings.
 
My PostgresSQL (9.2) is crashing after certain load tests. Currently, postgressql is crashing when simulatenously 800 to 1000 threads are run on a 10 million records schema. Not sure, if we have to tweak some more parameters of postgres. Currently, the postgressql is configured as below on a 7GB Ram on an Intel Xeon CPU E5507 2.27 GZ. Is this postgres limitation to support only 800 threads or any other configuration required. Please look at the log as below with errors. Please reply
 
 
max_connections 5000
shared_buffers 2024 MB
synchronous_commitoff
wal_buffers100 MB
wal_writer_delays1000ms
checkpoint_segments512
checkpoint_timeout5 min
checkpoint_completion_target0.5
checkpoint_warning30s
work_memory1G
effective_cache_size5 GB
 
 
 
2013-06-11 15:11:17 GMT [26201]: [1-1]ERROR: canceling autovacuum task

2013-06-11 15:11:17 GMT [26201]: [2-1]CONTEXT: automatic vacuum of table "newrelic.tenant1.customer"

2013-06-11 15:11:17 GMT [25242]: [1-1]LOG: sending cancel to blocking autovacuum PID 26201

2013-06-11 15:11:17 GMT [25242]: [2-1]DETAIL: Process 25242 waits for ExclusiveLock on extension of relation 679054 of database 666546.

2013-06-11 15:11:17 GMT [25242]: [3-1]STATEMENT: UPDATE tenant1.customer SET lastmodifieddate = $1 WHERE id IN ( select random_range((select min(id) from tenant1.customer ), (select max(id) from tenant1.customer )) as id ) AND softdeleteflag IS NOT TRUE

2013-06-11 15:11:17 GMT [25242]: [4-1]WARNING: could not send signal to process 26201: No such process

2013-06-11 15:22:29 GMT [22229]: [11-1]WARNING: worker took too long to start; canceled

2013-06-11 15:24:10 GMT [26511]: [1-1]WARNING: autovacuum worker started without a worker entry

2013-06-11 16:03:33 GMT [23092]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:06:05 GMT [23222]: [5-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:07:06 GMT [26869]: [1-1]FATAL: canceling authentication due to timeout

2013-06-11 16:23:16 GMT [25128]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:23:20 GMT [25128]: [2-1]LOG: unexpected EOF on client connection with an open transaction

2013-06-11 16:30:56 GMT [23695]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:43:55 GMT [24618]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:44:29 GMT [25204]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:54:14 GMT [22226]: [1-1]PANIC: stuck spinlock (0x2aaab54279d4) detected at bufmgr.c:1239

2013-06-11 16:54:14 GMT [32521]: [8-1]LOG: checkpointer process (PID 22226) was terminated by signal 6: Aborted

2013-06-11 16:54:14 GMT [32521]: [9-1]LOG: terminating any other active server processes

2013-06-11 16:54:14 GMT [26931]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:54:14 GMT [26931]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.

2013-06-11 16:54:14 GMT [26931]: [3-1]HINT: In a moment you should be able to reconnect to the database and repeat your command.

2013-06-11 16:54:14 GMT [26401]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:54:14 GMT [26401]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
 
2013-06-11 16:55:08 GMT [27579]: [1-1]FATAL: the database system is in recovery mode

2013-06-11 16:55:08 GMT [24041]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:55:08 GMT [24041]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current
 

Re: [GENERAL] Postgres DB crashing

From
AI Rumman
Date:
Stop the autovacuum process and try again.


On Tue, Jun 18, 2013 at 1:31 PM, bhanu udaya <udayabhanu1984@hotmail.com> wrote:
Hello,
Greetings.
 
My PostgresSQL (9.2) is crashing after certain load tests. Currently, postgressql is crashing when simulatenously 800 to 1000 threads are run on a 10 million records schema. Not sure, if we have to tweak some more parameters of postgres. Currently, the postgressql is configured as below on a 7GB Ram on an Intel Xeon CPU E5507 2.27 GZ. Is this postgres limitation to support only 800 threads or any other configuration required. Please look at the log as below with errors. Please reply
 
 
max_connections 5000
shared_buffers 2024 MB
synchronous_commitoff
wal_buffers100 MB
wal_writer_delays1000ms
checkpoint_segments512
checkpoint_timeout5 min
checkpoint_completion_target0.5
checkpoint_warning30s
work_memory1G
effective_cache_size5 GB
 
 
 
2013-06-11 15:11:17 GMT [26201]: [1-1]ERROR: canceling autovacuum task

2013-06-11 15:11:17 GMT [26201]: [2-1]CONTEXT: automatic vacuum of table "newrelic.tenant1.customer"

2013-06-11 15:11:17 GMT [25242]: [1-1]LOG: sending cancel to blocking autovacuum PID 26201

2013-06-11 15:11:17 GMT [25242]: [2-1]DETAIL: Process 25242 waits for ExclusiveLock on extension of relation 679054 of database 666546.

2013-06-11 15:11:17 GMT [25242]: [3-1]STATEMENT: UPDATE tenant1.customer SET lastmodifieddate = $1 WHERE id IN ( select random_range((select min(id) from tenant1.customer ), (select max(id) from tenant1.customer )) as id ) AND softdeleteflag IS NOT TRUE

2013-06-11 15:11:17 GMT [25242]: [4-1]WARNING: could not send signal to process 26201: No such process

2013-06-11 15:22:29 GMT [22229]: [11-1]WARNING: worker took too long to start; canceled

2013-06-11 15:24:10 GMT [26511]: [1-1]WARNING: autovacuum worker started without a worker entry

2013-06-11 16:03:33 GMT [23092]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:06:05 GMT [23222]: [5-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:07:06 GMT [26869]: [1-1]FATAL: canceling authentication due to timeout

2013-06-11 16:23:16 GMT [25128]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:23:20 GMT [25128]: [2-1]LOG: unexpected EOF on client connection with an open transaction

2013-06-11 16:30:56 GMT [23695]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:43:55 GMT [24618]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:44:29 GMT [25204]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:54:14 GMT [22226]: [1-1]PANIC: stuck spinlock (0x2aaab54279d4) detected at bufmgr.c:1239

2013-06-11 16:54:14 GMT [32521]: [8-1]LOG: checkpointer process (PID 22226) was terminated by signal 6: Aborted

2013-06-11 16:54:14 GMT [32521]: [9-1]LOG: terminating any other active server processes

2013-06-11 16:54:14 GMT [26931]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:54:14 GMT [26931]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.

2013-06-11 16:54:14 GMT [26931]: [3-1]HINT: In a moment you should be able to reconnect to the database and repeat your command.

2013-06-11 16:54:14 GMT [26401]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:54:14 GMT [26401]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
 
2013-06-11 16:55:08 GMT [27579]: [1-1]FATAL: the database system is in recovery mode

2013-06-11 16:55:08 GMT [24041]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:55:08 GMT [24041]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current
 

Re: [GENERAL] Postgres DB crashing

From
bhanu udaya
Date:
Thanks for the quick response. These errors are after disabling the autovacuum.  auto_vacuum parameter was set to off.
 Can find the exact reason for this crash. 
 
Thanks and Regards
Radha Krishna

Date: Tue, 18 Jun 2013 13:54:09 -0400
Subject: Re: [pgadmin-support] [GENERAL] Postgres DB crashing
From: rummandba@gmail.com
To: udayabhanu1984@hotmail.com
CC: kgrittn@mail.com; adrian.klaver@gmail.com; pgsql-general@postgresql.org; pgadmin-support@postgresql.org; laurenz.albe@wien.gv.at; chris.travers@gmail.com; magnus@hagander.net

Stop the autovacuum process and try again.


On Tue, Jun 18, 2013 at 1:31 PM, bhanu udaya <udayabhanu1984@hotmail.com> wrote:
Hello,
Greetings.
 
My PostgresSQL (9.2) is crashing after certain load tests. Currently, postgressql is crashing when simulatenously 800 to 1000 threads are run on a 10 million records schema. Not sure, if we have to tweak some more parameters of postgres. Currently, the postgressql is configured as below on a 7GB Ram on an Intel Xeon CPU E5507 2.27 GZ. Is this postgres limitation to support only 800 threads or any other configuration required. Please look at the log as below with errors. Please reply
 
 
max_connections 5000
shared_buffers 2024 MB
synchronous_commitoff
wal_buffers100 MB
wal_writer_delays1000ms
checkpoint_segments512
checkpoint_timeout5 min
checkpoint_completion_target0.5
checkpoint_warning30s
work_memory1G
effective_cache_size5 GB
 
 
 
2013-06-11 15:11:17 GMT [26201]: [1-1]ERROR: canceling autovacuum task

2013-06-11 15:11:17 GMT [26201]: [2-1]CONTEXT: automatic vacuum of table "newrelic.tenant1.customer"

2013-06-11 15:11:17 GMT [25242]: [1-1]LOG: sending cancel to blocking autovacuum PID 26201

2013-06-11 15:11:17 GMT [25242]: [2-1]DETAIL: Process 25242 waits for ExclusiveLock on extension of relation 679054 of database 666546.

2013-06-11 15:11:17 GMT [25242]: [3-1]STATEMENT: UPDATE tenant1.customer SET lastmodifieddate = $1 WHERE id IN ( select random_range((select min(id) from tenant1.customer ), (select max(id) from tenant1.customer )) as id ) AND softdeleteflag IS NOT TRUE

2013-06-11 15:11:17 GMT [25242]: [4-1]WARNING: could not send signal to process 26201: No such process

2013-06-11 15:22:29 GMT [22229]: [11-1]WARNING: worker took too long to start; canceled

2013-06-11 15:24:10 GMT [26511]: [1-1]WARNING: autovacuum worker started without a worker entry

2013-06-11 16:03:33 GMT [23092]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:06:05 GMT [23222]: [5-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:07:06 GMT [26869]: [1-1]FATAL: canceling authentication due to timeout

2013-06-11 16:23:16 GMT [25128]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:23:20 GMT [25128]: [2-1]LOG: unexpected EOF on client connection with an open transaction

2013-06-11 16:30:56 GMT [23695]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:43:55 GMT [24618]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:44:29 GMT [25204]: [1-1]LOG: could not receive data from client: Connection timed out

2013-06-11 16:54:14 GMT [22226]: [1-1]PANIC: stuck spinlock (0x2aaab54279d4) detected at bufmgr.c:1239

2013-06-11 16:54:14 GMT [32521]: [8-1]LOG: checkpointer process (PID 22226) was terminated by signal 6: Aborted

2013-06-11 16:54:14 GMT [32521]: [9-1]LOG: terminating any other active server processes

2013-06-11 16:54:14 GMT [26931]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:54:14 GMT [26931]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.

2013-06-11 16:54:14 GMT [26931]: [3-1]HINT: In a moment you should be able to reconnect to the database and repeat your command.

2013-06-11 16:54:14 GMT [26401]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:54:14 GMT [26401]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
 
2013-06-11 16:55:08 GMT [27579]: [1-1]FATAL: the database system is in recovery mode

2013-06-11 16:55:08 GMT [24041]: [1-1]WARNING: terminating connection because of crash of another server process

2013-06-11 16:55:08 GMT [24041]: [2-1]DETAIL: The postmaster has commanded this server process to roll back the current
 

Re: [GENERAL] Postgres DB crashing

From
Richard Huxton
Date:
On 18/06/13 18:31, bhanu udaya wrote:
> Hello,
> Greetings.
>
> My PostgresSQL (9.2) is crashing after certain load tests. Currently,
> postgressql is crashing when simulatenously 800 to 1000 threads are run
> on a 10 million records schema. Not sure, if we have to tweak some more
> parameters of postgres. Currently, the postgressql is configured as
> below on a 7GB Ram on an Intel Xeon CPU E5507 2.27 GZ. Is this postgres
> limitation to support only 800 threads or any other configuration
> required. Please look at the log as below with errors. Please reply
>
>
> max_connections    5000
> shared_buffers    2024 MB
> synchronous_commit     off
> wal_buffers     100 MB
> wal_writer_delays     1000ms
> checkpoint_segments     512
> checkpoint_timeout     5 min
> checkpoint_completion_target     0.5
> checkpoint_warning     30s
> work_memory     1G
> effective_cache_size     5 GB

Just to point out, your memory settings are set to allow *at least*

  shared-buffers 2GB + (5000 * 1GB) = 5TB+

You don't have that much memory. You probably don't have that much disk.
This is never going to work.

As has been said, there's no way you can do useful work simultaneously
with 1000 threads if you only have 4 cores - use a connection pooler.
You'll also need to reduce work_mem to 1MB or so.

--
   Richard Huxton
   Archonet Ltd


Re: [GENERAL] Postgres DB crashing

From
Merlin Moncure
Date:
On Thu, Jun 20, 2013 at 5:17 AM, Richard Huxton <dev@archonet.com> wrote:
> On 18/06/13 18:31, bhanu udaya wrote:
>>
>> Hello,
>> Greetings.
>>
>> My PostgresSQL (9.2) is crashing after certain load tests. Currently,
>> postgressql is crashing when simulatenously 800 to 1000 threads are run
>> on a 10 million records schema. Not sure, if we have to tweak some more
>> parameters of postgres. Currently, the postgressql is configured as
>> below on a 7GB Ram on an Intel Xeon CPU E5507 2.27 GZ. Is this postgres
>> limitation to support only 800 threads or any other configuration
>> required. Please look at the log as below with errors. Please reply
>>
>>
>> max_connections 5000
>> shared_buffers  2024 MB
>> synchronous_commit      off
>> wal_buffers     100 MB
>> wal_writer_delays       1000ms
>> checkpoint_segments     512
>> checkpoint_timeout      5 min
>> checkpoint_completion_target    0.5
>> checkpoint_warning      30s
>> work_memory     1G
>> effective_cache_size    5 GB
>
>
> Just to point out, your memory settings are set to allow *at least*
>
>  shared-buffers 2GB + (5000 * 1GB) = 5TB+
>
> You don't have that much memory. You probably don't have that much disk.
> This is never going to work.
>
> As has been said, there's no way you can do useful work simultaneously with
> 1000 threads if you only have 4 cores - use a connection pooler. You'll also
> need to reduce work_mem to 1MB or so.

aside: if you have particular query that needs extra work_mem, you can
always temporarily raise it at run time (unlike shared buffers).

OP needs to explore use of connection pooler, in particular pgbouncer.
 Anyways none of this explains why the server is actually crashing.

merlin


Postgres case insensitive searches

From
bhanu udaya
Date:
Hello,
 
Grettings,
 
What is the best way of doing case insensitive searches in postgres using Like.
 
Ilike - does not use indexes
function based indexes are not as fast as required.
CITEXT - it still taking 600 ms - 1 second on a 2.2 million rows... does not use index
Collation Indexes creation with POSIX - does not really work.
GIST/GIN indexes are faster when using like, but not case insenstive.
 
Is there a better way of resolving this case insenstive searches with fast retrieval.
 
Thanks and Regards
Radha Krishna
 

Re: Postgres case insensitive searches

From
bhanu udaya
Date:
Thanks. But, I do not want to convert into upper and show the result. 
Example, if I have records as below:
id  type
1. abcd
2. Abcdef
3. ABcdefg
4. aaadf
 
The below query should report all the above
 
select * from table where type like 'ab%'. It should get all above 3 records.  Is there a way the database itself can be made case-insensitive with UTF8 characterset. I tried with character type & collation POSIX, but it did not really help.
 
Thanks and Regards
Radha Krishna
 
> From: laurenz.albe@wien.gv.at
> To: udayabhanu1984@hotmail.com; pgsql-general@postgresql.org
> Subject: RE: Postgres case insensitive searches
> Date: Fri, 28 Jun 2013 12:32:00 +0000
>
> bhanu udaya wrote:
> > What is the best way of doing case insensitive searches in postgres using Like.
>
> Table "laurenz.t"
> Column | Type | Modifiers
> --------+---------+-----------
> id | integer | not null
> val | text | not null
> Indexes:
> "t_pkey" PRIMARY KEY, btree (id)
>
>
> CREATE INDEX t_val_ci_ind ON t ((upper(val) text_pattern_ops);
>
> ANALYZE t;
>
> EXPLAIN SELECT id FROM t WHERE upper(val) LIKE 'AB%';
>
> QUERY PLAN
> ------------------------------------------------------------------------------
> Index Scan using t_val_ci_ind on t (cost=0.01..8.28 rows=1 width=4)
> Index Cond: ((upper(val) ~>=~ 'AB'::text) AND (upper(val) ~<~ 'AC'::text))
> Filter: (upper(val) ~~ 'AB%'::text)
> (3 rows)
>
> Yours,
> Laurenz Albe

Re: [GENERAL] Postgres case insensitive searches

From
Alban Hertroys
Date:
On Jun 29, 2013, at 3:59, bhanu udaya <udayabhanu1984@hotmail.com> wrote:

> Thanks. But, I do not want to convert into upper and show the result.

Why not? It won't modify your results, just the search condition:

SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY val;

Or:

SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY upper(val), val;


> Example, if I have records as below:
> id  type
> 1. abcd
> 2. Abcdef
> 3. ABcdefg
> 4. aaadf
>
> The below query should report all the above
>
> select * from table where type like 'ab%'. It should get all above 3 records.  Is there a way the database itself can
bemade case-insensitive with UTF8 characterset. I tried with character type & collation POSIX, but it did not really
help.

I was under the impression this would work, but ISTR that not every OS has this capability (Postgres makes use of the
OScollation mechanics). So, what OS are you running the server on? 

> > From: laurenz.albe@wien.gv.at
> > To: udayabhanu1984@hotmail.com; pgsql-general@postgresql.org
> > Subject: RE: Postgres case insensitive searches
> > Date: Fri, 28 Jun 2013 12:32:00 +0000

Please do not top-post on this list.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



Re: [GENERAL] Postgres case insensitive searches

From
bhanu udaya
Date:
Hello,
I agree that it is just search condition. But, in a 2.5 million record table search, upper function is not that fast.  The expectation is to get the query retrieved in 100 ms...with all indexes used.
 
I tried with upper, Citext, but the result set was more than a second.
 
The OS server we are using is Linux 64 bit.
 
Thanks and Regards
Radha Krishna
 
> Subject: Re: [pgadmin-support] [GENERAL] Postgres case insensitive searches
> From: haramrae@gmail.com
> Date: Sat, 29 Jun 2013 09:37:51 +0200
> CC: laurenz.albe@wien.gv.at; pgsql-general@postgresql.org; pgadmin-support@postgresql.org
> To: udayabhanu1984@hotmail.com
>
> On Jun 29, 2013, at 3:59, bhanu udaya <udayabhanu1984@hotmail.com> wrote:
>
> > Thanks. But, I do not want to convert into upper and show the result.
>
> Why not? It won't modify your results, just the search condition:
>
> SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY val;
>
> Or:
>
> SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY upper(val), val;
>
>
> > Example, if I have records as below:
> > id type
> > 1. abcd
> > 2. Abcdef
> > 3. ABcdefg
> > 4. aaadf
> >
> > The below query should report all the above
> >
> > select * from table where type like 'ab%'. It should get all above 3 records. Is there a way the database itself can be made case-insensitive with UTF8 characterset. I tried with character type & collation POSIX, but it did not really help.
>
> I was under the impression this would work, but ISTR that not every OS has this capability (Postgres makes use of the OS collation mechanics). So, what OS are you running the server on?
>
> > > From: laurenz.albe@wien.gv.at
> > > To: udayabhanu1984@hotmail.com; pgsql-general@postgresql.org
> > > Subject: RE: Postgres case insensitive searches
> > > Date: Fri, 28 Jun 2013 12:32:00 +0000
>
> Please do not top-post on this list.
>
> Alban Hertroys
> --
> If you can't see the forest for the trees,
> cut the trees and you'll find there is no forest.
>
>
>
> --
> Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-support

Re: [GENERAL] Postgres case insensitive searches

From
Alban Hertroys
Date:
On Jun 29, 2013, at 15:02, bhanu udaya <udayabhanu1984@hotmail.com> wrote:

> I agree that it is just search condition. But, in a 2.5 million record table search, upper function is not that fast.
 

Suit yourself, the solution is there.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



Re: [GENERAL] Postgres case insensitive searches

From
Lee Hachadoorian
Date:
On 06/29/2013 09:02 AM, bhanu udaya wrote:<br /><blockquote cite="mid:COL127-W1529DEA2A427BDB5A28C9FD3770@phx.gbl"
type="cite"><style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style><div dir="ltr">Hello,<br /> I agree that it is just search condition. But, in a 2.5 million record table
search,upper function is not that fast.  The expectation is to get the query retrieved in 100 ms...with all indexes
used.<br/>  <br /> I tried with upper, Citext, but the result set was more than a second.<br />  <br /> The OS server
weare using is Linux 64 bit.<br />  <br /> Thanks and Regards<br /> Radha Krishna<br />  <br /><div>> Subject: Re:
[pgadmin-support][GENERAL] Postgres case insensitive searches<br /> > From: <a class="moz-txt-link-abbreviated"
href="mailto:haramrae@gmail.com">haramrae@gmail.com</a><br/> > Date: Sat, 29 Jun 2013 09:37:51 +0200<br /> > CC:
<aclass="moz-txt-link-abbreviated" href="mailto:laurenz.albe@wien.gv.at">laurenz.albe@wien.gv.at</a>; <a
class="moz-txt-link-abbreviated"href="mailto:pgsql-general@postgresql.org">pgsql-general@postgresql.org</a>; <a
class="moz-txt-link-abbreviated"href="mailto:pgadmin-support@postgresql.org">pgadmin-support@postgresql.org</a><br />
>To: <a class="moz-txt-link-abbreviated" href="mailto:udayabhanu1984@hotmail.com">udayabhanu1984@hotmail.com</a><br
/>> <br /> > On Jun 29, 2013, at 3:59, bhanu udaya <a class="moz-txt-link-rfc2396E"
href="mailto:udayabhanu1984@hotmail.com"><udayabhanu1984@hotmail.com></a>wrote:<br /> > <br /> > >
Thanks.But, I do not want to convert into upper and show the result. <br /> > <br /> > Why not? It won't modify
yourresults, just the search condition:<br /> > <br /> > SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER
BYval;<br /> > <br /> > Or:<br /> > <br /> > SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY
upper(val),val;<br /> > <br /> > <br /> > > Example, if I have records as below:<br /> > > id type<br
/>> > 1. abcd<br /> > > 2. Abcdef<br /> > > 3. ABcdefg<br /> > > 4. aaadf<br /> > > <br
/>> > The below query should report all the above <br /> > > <br /> > > select * from table where
typelike 'ab%'. It should get all above 3 records. Is there a way the database itself can be made case-insensitive with
UTF8characterset. I tried with character type & collation POSIX, but it did not really help.<br /> > <br /> >
Iwas under the impression this would work, but ISTR that not every OS has this capability (Postgres makes use of the OS
collationmechanics). So, what OS are you running the server on?<br /> > <br /></div></div></blockquote><br />
Duplicatethe column with an upper or lowercase version and run all queries against that.<br /><br /> CREATE TABLE foo
(<br/>     id serial PRIMARY KEY,<br />     val text,<br />     val_lower text<br /> );<br /><br /> Index val_lower.
Usetriggers to keep val and val_lower in sync and discard all attempts to write directly to val_lower. Then all queries
wouldbe of the form<br /><br /> SELECT id, val<br /> FROM foo<br /> WHERE val_lower LIKE 'ab%';<br /><br /> Wouldn't
wantto write every table like this, but if (a) query speed trumps all other requirements and (b) functional index,
CITEXT,etc. have all been rejected as not fast enough…<br /><br /> --Lee<br /><br /><br /><pre class="moz-signature"
cols="72">--
 
Lee Hachadoorian
Assistant Professor in Geography, Dartmouth College
<a class="moz-txt-link-freetext" href="http://freecity.commons.gc.cuny.edu">http://freecity.commons.gc.cuny.edu</a>
</pre>

Re: [GENERAL] Postgres case insensitive searches

From
bhanu udaya
Date:
 

> Subject: Re: [pgadmin-support] [GENERAL] Postgres case insensitive searches
> From: haramrae@gmail.com
> Date: Sat, 29 Jun 2013 09:37:51 +0200
> CC: laurenz.albe@wien.gv.at; pgsql-general@postgresql.org; pgadmin-support@postgresql.org
> To: udayabhanu1984@hotmail.com
>
> On Jun 29, 2013, at 3:59, bhanu udaya <udayabhanu1984@hotmail.com> wrote:
>
> > Thanks. But, I do not want to convert into upper and show the result.
>
> Why not? It won't modify your results, just the search condition:
>
> SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY val;
>
> Or:
>
> SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER BY upper(val), val;
>
>
> > Example, if I have records as below:
> > id type
> > 1. abcd
> > 2. Abcdef
> > 3. ABcdefg
> > 4. aaadf
> >
> > The below query should report all the above
> >
> > select * from table where type like 'ab%'. It should get all above 3 records. Is there a way the database itself can be made case-insensitive with UTF8 characterset. I tried with character type & collation POSIX, but it did not really help.
>
> I was under the impression this would work, but ISTR that not every OS has this capability (Postgres makes use of the OS collation mechanics). So, what OS are you running the server on?
>

Duplicate the column with an upper or lowercase version and run all queries against that.

CREATE TABLE foo (
    id serial PRIMARY KEY,
    val text,
    val_lower text
);

Index val_lower. Use triggers to keep val and val_lower in sync and discard all attempts to write directly to val_lower. Then all queries would be of the form

SELECT id, val
FROM foo
WHERE val_lower LIKE 'ab%';

Wouldn't want to write every table like this, but if (a) query speed trumps all other requirements and (b) functional index, CITEXT, etc. have all been rejected as not fast enough…

--Lee


-- 
Lee Hachadoorian
Assistant Professor in Geography, Dartmouth College
http://freecity.commons.gc.cuny.edu
It is a good idea to have a duplicate column and index and use that column. But, we have heavy
inserts/updates on this table. I am afraid that it would slow down the insert performance. 
But, I would definately like to test this option. Isn't it better to convert Postgres DB to case insensitive ?
How difficult is that ? I want the DB to support UTF8 and be case insensitive like SQL Server.
 
Thanks

Re: [GENERAL] Postgres case insensitive searches

From
bhanu udaya
Date:
Yes. I have used analyze table, and also I have explain plan the CITEXT query. It was not using Index. It is not primary and it is surprised to know that CITEXT would use index only if it is a primary key column. Interesting and new thing to know.
 
Upper and Lower functions are not right choice when the table is > 2.5 million and where we also have heavy insert transactions.

I doubt, if we can cache the table if there are frequent inserts/updates.  The good idea would be to get the DB to case insenstive configuration like SQL Server. I would go for this solution, if postgres supports.
 
Thanks for all the replies and help.
 
> Date: Sat, 29 Jun 2013 09:02:12 -0700
> From: jd@commandprompt.com
> To: udayabhanu1984@hotmail.com
> CC: kgrittn@mail.com; adrian.klaver@gmail.com; pgsql-general@postgresql.org; pgadmin-support@postgresql.org; laurenz.albe@wien.gv.at; chris.travers@gmail.com; magnus@hagander.net
> Subject: Re: [GENERAL] Postgres case insensitive searches
>
>
> On 06/28/2013 03:21 AM, bhanu udaya wrote:
> > Hello,
> >
> > Grettings,
> >
> > What is the best way of doing case insensitive searches in postgres
> > using Like.
> >
> > Ilike - does not use indexes
> > function based indexes are not as fast as required.
> > CITEXT - it still taking 600 ms - 1 second on a 2.2 million rows... does
> > not use index
> > Collation Indexes creation with POSIX - does not really work.
> > GIST/GIN indexes are faster when using like, but not case insenstive.
> >
> > Is there a better way of resolving this case insenstive searches with
> > fast retrieval.
>
> O.k. there is not anywhere near enough information here to provide you
> with a proper answer but here are the two things you should look at:
>
> CITEXT: You said it takes 600ms - 1 second. Is that a first run or is
> the relation cached? Second how do you know it isn't using the index?
> Have you ran an explain analyze? In order for CITEXT to use an index it
> the value being searched must be the PRIMARY KEY, is your column the
> primary key?
>
> Second, you have provided us with zero information on your hardware
> configuration. 2.2 million rows is a low of rows to seqscan, if they
> aren't cached or if you don't have reasonable hardware it is going to
> take time no matter what you do.
>
> Third, have you tried this with unlogged tables (for performance)?
>
> Fourth, there was another person that suggested using UPPER() that is a
> reasonable suggestion. The docs clearly suggest using lower(), I don't
> actually know if there is a difference but that is the common way to do
> it and it will use an index IF you make a functional index on the column
> using lower.
>
> JD
>
>
>
>
> >
> > Thanks and Regards
> > Radha Krishna
> >
>
>
> --
> Command Prompt, Inc. - http://www.commandprompt.com/ 509-416-6579
> PostgreSQL Support, Training, Professional Services and Development
> High Availability, Oracle Conversion, Postgres-XC, @cmdpromptinc
> For my dreams of your image that blossoms
> a rose in the deeps of my heart. - W.B. Yeats

Re: [GENERAL] Postgres case insensitive searches

From
"Joshua D. Drake"
Date:
On 06/28/2013 03:21 AM, bhanu udaya wrote:
> Hello,
>
> Grettings,
>
> What is the best way of doing case insensitive searches in postgres
> using Like.
>
> Ilike - does not use indexes
> function based indexes are not as fast as required.
> CITEXT - it still taking 600 ms - 1 second on a 2.2 million rows... does
> not use index
> Collation Indexes creation with POSIX - does not really work.
> GIST/GIN indexes are faster when using like, but not case insenstive.
>
> Is there a better way of resolving this case insenstive searches with
> fast retrieval.

O.k. there is not anywhere near enough information here to provide you
with a proper answer but here are the two things you should look at:

CITEXT: You said it takes 600ms - 1 second. Is that a first run or is
the relation cached? Second how do you know it isn't using the index?
Have you ran an explain analyze? In order for CITEXT to use an index it
the value being searched must be the PRIMARY KEY, is your column the
primary key?

Second, you have provided us with zero information on your hardware
configuration. 2.2 million rows is a low of rows to seqscan, if they
aren't cached or if you don't have reasonable hardware it is going to
take time no matter what you do.

Third, have you tried this with unlogged tables (for performance)?

Fourth, there was another person that suggested using UPPER() that is a
reasonable suggestion. The docs clearly suggest using lower(), I don't
actually know if there is a difference but that is the common way to do
it and it will use an index IF you make a functional index on the column
using lower.

JD




>
> Thanks and Regards
> Radha Krishna
>


--
Command Prompt, Inc. - http://www.commandprompt.com/  509-416-6579
PostgreSQL Support, Training, Professional Services and Development
High Availability, Oracle Conversion, Postgres-XC, @cmdpromptinc
For my dreams of your image that blossoms
    a rose in the deeps of my heart. - W.B. Yeats


Re: [GENERAL] Postgres case insensitive searches

From
"Joshua D. Drake"
Date:
On 06/29/2013 09:24 AM, bhanu udaya wrote:

> Upper and Lower functions are not right choice when the table is > 2.5
> million and where we also have heavy insert transactions.

Prove it. Seriously, just run a test case against it. See how it works
for you. Inserts are generally a very inexpensive operation with Postgres.

>
> I doubt, if we can cache the table if there are frequent
> inserts/updates.  The good idea would be to get the DB to case
> insenstive configuration like SQL Server. I would go for this solution,
> if postgres supports.

Postgres does not.

And as Jon said, maybe Postgres isn't the right solution for you. That
would be a bummer but we can't be all things to all people.


JD

--
Command Prompt, Inc. - http://www.commandprompt.com/  509-416-6579
PostgreSQL Support, Training, Professional Services and Development
High Availability, Oracle Conversion, Postgres-XC, @cmdpromptinc
For my dreams of your image that blossoms
    a rose in the deeps of my heart. - W.B. Yeats


Re: [GENERAL] Postgres case insensitive searches

From
Michael Shapiro
Date:
I have a table called jobs with ~17 millions records. Without an index on the queue column, the following query

      select count(*) from jobs where lower(queue) = 'normal'

found ~2.6 millions records in 10160ms

With the following index:

     create index lower_queue on jobs (lower(queue))

the same query only took 3850ms


On Sat, Jun 29, 2013 at 2:08 PM, Joshua D. Drake <jd@commandprompt.com> wrote:

On 06/29/2013 09:24 AM, bhanu udaya wrote:

Upper and Lower functions are not right choice when the table is > 2.5
million and where we also have heavy insert transactions.

Prove it. Seriously, just run a test case against it. See how it works for you. Inserts are generally a very inexpensive operation with Postgres.


I doubt, if we can cache the table if there are frequent
inserts/updates.  The good idea would be to get the DB to case
insenstive configuration like SQL Server. I would go for this solution,
if postgres supports.

Postgres does not.

And as Jon said, maybe Postgres isn't the right solution for you. That would be a bummer but we can't be all things to all people.


JD

--
Command Prompt, Inc. - http://www.commandprompt.com/  509-416-6579
PostgreSQL Support, Training, Professional Services and Development
High Availability, Oracle Conversion, Postgres-XC, @cmdpromptinc
For my dreams of your image that blossoms
   a rose in the deeps of my heart. - W.B. Yeats


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

Re: Postgres case insensitive searches

From
Albe Laurenz
Date:
bhanu udaya wrote:
>>> What is the best way of doing case insensitive searches in postgres using Like.
>>
>> Table "laurenz.t"
>> Column | Type | Modifiers
>> --------+---------+-----------
>> id | integer | not null
>> val | text | not null
>> Indexes:
>> "t_pkey" PRIMARY KEY, btree (id)
>>
>>
>> CREATE INDEX t_val_ci_ind ON t ((upper(val) text_pattern_ops);
>>
>> ANALYZE t;
>>
>> EXPLAIN SELECT id FROM t WHERE upper(val) LIKE 'AB%';
>>
>> QUERY PLAN
>> ------------------------------------------------------------------------------
>> Index Scan using t_val_ci_ind on t (cost=0.01..8.28 rows=1 width=4)
>> Index Cond: ((upper(val) ~>=~ 'AB'::text) AND (upper(val) ~<~ 'AC'::text))
>> Filter: (upper(val) ~~ 'AB%'::text)
>> (3 rows)

> Thanks. But, I do not want to convert into upper and show the result.
> Example, if I have records as below:
> id  type
> 1. abcd
> 2. Abcdef
> 3. ABcdefg
> 4. aaadf
> 
> The below query should report all the above

No, it shouldn't :^)

> select * from table where type like 'ab%'. It should get all above 3 records.  Is there a way the
> database itself can be made case-insensitive with UTF8 characterset. I tried with character type &
> collation POSIX, but it did not really help.

My solution is fast and efficient, it will call upper() only once
per query.  I don't see your problem.  Different database systems
do things in different ways, but as long as you can do what you need
to do, that should be good enough.

Yours,
Laurenz Albe