Sunday, August 3, 2008

Re: [pgsql-es-ayuda] retornar varias filas de un pl pgsql

2008/8/3 Ana María Mandiola Fernández <amandiola@gmail.com>:
> HOLa !!
> soy nuevo en lenguaje de bdatos, alguien que me ayude con una funcion que
> devuelva mas de un registro de una tabla, he intentado con record,
> refcursores y ninguna me sale , a lo mas tiro una fila pero tengo 8 filas,
> registros tuplas, en mi tabla prestadora, como lo hago??' tengo esta funcion
> q devuelve una sola fila.
>

nuevo, eh? leer el manual no hace daño ;)

> CREATE OR REPLACE FUNCTION p5()
> RETURNS record AS
> $BODY$DECLARE
> algo RECORD;
> BEGIN
>
> SELECT INTO algo * FROM prestadora;
>
> return algo;
> END;$BODY$
> LANGUAGE 'plpgsql'
>

CREATE OR REPLACE FUNCTION p5() RETURNS SETOF prestadora AS
$BODY$

SELECT INTO algo * FROM prestadora;

$BODY$
LANGUAGE 'sql'

ahora que si lo quieres hacer en plpgsql (posiblemente porque quieras
procesar datos antes de devolverlos)

CREATE OR REPLACE FUNCTION p5() RETURNS SETOF prestadora AS
$BODY$
DECLARE
algo RECORD;
BEGIN
for algo in SELECT * FROM prestadora loop
return next algo;
end loop;
return;
END;
$BODY$
LANGUAGE 'plpgsql'

o en 8.3

CREATE OR REPLACE FUNCTION p5() RETURNS SETOF prestadora AS
$BODY$
BEGIN
return query select * from prestadora;
END;
$BODY$
LANGUAGE 'plpgsql'

o con cursores o de 1001 formas mas...

la clave estuvo en el SETOF

--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Guayaquil - Ecuador
Cel. (593) 87171157
--
TIP 8: explain analyze es tu amigo

Re: [GENERAL] bytea encode performance issues

Tom Lane wrote:
> Could we see EXPLAIN ANALYZE, not EXPLAIN? Without actual facts
> to work from, any suggestions would be mere guesswork.

This was taken immediately after a vacuum analyze on the database.

"HashAggregate (cost=41596.68..41596.84 rows=16 width=764) (actual
time=488263.802..488263.837 rows=40 loops=1)"
" -> Nested Loop (cost=0.00..41596.60 rows=16 width=764) (actual
time=23375.445..488260.311 rows=40 loops=1)"
" -> Nested Loop (cost=0.00..41463.32 rows=16 width=780)
(actual time=23375.344..488231.994 rows=40 loops=1)"
" -> Seq Scan on dbmail_messageblks k
(cost=0.00..39193.21 rows=259 width=764) (actual time=30.662..486585.126
rows=2107 loops=1)"
" Filter: ((is_header = 0::smallint) AND
(encode(messageblk, 'escape'::text) ~~ '%Yossi%'::text))"
" -> Index Scan using dbmail_messages_2 on dbmail_messages
m (cost=0.00..8.75 rows=1 width=16) (actual time=0.777..0.777 rows=0
loops=2107)"
" Index Cond: (m.physmessage_id = k.physmessage_id)"
" Filter: ((mailbox_idnr = 8) AND (status = ANY
('{0,1}'::integer[])))"
" -> Index Scan using dbmail_physmessage_pkey on
dbmail_physmessage p (cost=0.00..8.32 rows=1 width=8) (actual
time=0.701..0.703 rows=1 loops=40)"
" Index Cond: (k.physmessage_id = p.id)"
"Total runtime: 488264.192 ms"


> Also, what can you tell us about the sizes of the messageblk
> strings (max and avg would be interesting)?
>
select max(length(messageblk)),avg(length(messageblk)) from
dbmail_messageblks
MAX AVG
532259; 48115.630147120314

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

Re: [pgsql-es-ayuda] Insertar

siempre manda una copia a la lista

2008/8/3 Luis Martínez <luisedgardomartinezlinares@gmail.com>:
>>
>> ¿Estoy usando una sentencia asi y me da error insert into
>> prueba2.prueba2.prueba select * from prueba1.public.prueba1? y obtengo el
>> siguiente error
>
> ERROR: cross-database references are not implemented:
> "prueba2.prueba2.prueba2"
> Estado SQL:0A000
> donde uso la declaracion de <base de datos>.<schema>.<tabla> quisiera saber
> que hago mal

me parece bastante claro, no puedes usar sentencias entre bases de
datos... para eso debes usar dblink o plproxy en modo de conexion

http://www.postgresql.org/docs/8.3/static/dblink.html
https://developer.skype.com/SkypeGarage/DbProjects/PlProxy


--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Guayaquil - Ecuador
Cel. (593) 87171157
--
TIP 4: No hagas 'kill -9' a postmaster

Re: [GENERAL] [OT] newsreader issue? (Was: bytea encode performance issues)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I got the response by email, but it was also addressed to the mailing
list. My response was also an email sent to the mailing list, not to the
newsgroup. I got one other response, that I do not see in the newsgroup.
And I will reply to it also using the mailing list.

Sim

Lew wrote:
> Sim Zacks wrote:
>> (quoting someone:)
>>> That LIKE operator is probably your problem. An unbounded LIKE like that
>>> (with a wildcard on both sides) means no index can be used, hence you
>>> get a sequential scan.
>
> Was the message to which you responded posted to the newsgroup? It
> isn't appearing in my newsreader.
>
> Who wrote the message you quoted (you failed to cite the source)?
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiWk20ACgkQjDX6szCBa+pwzwCffdE3KZAg0f2TjUiq+gFCOrML
HM4An2wcV9G9aAE+94DH6Vwc6deMIHB4
=N0v/
-----END PGP SIGNATURE-----

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

Re: [HACKERS] Mini improvement: statement_cost_limit

Josh Berkus wrote:
> Tom,
>
>
>> Wasn't this exact proposal discussed and rejected awhile back?
>>
>
> We rejected Greenplum's much more invasive resource manager, because it
> created a large performance penalty on small queries whether or not it was
> turned on. However, I don't remember any rejection of an idea as simple
> as a cost limit rejection.
>
> This would, IMHO, be very useful for production instances of PostgreSQL.
> The penalty for mis-rejection of a poorly costed query is much lower than
> the penalty for having a bad query eat all your CPU.
>
>
Greenplum's introduced a way to creating a cost "threshold" a bit like
the way Simon was going to do "shared" work_mem. It did 2 things:

1/ Counted the cost of an about-to-be run query against the threshold,
and made the query wait if it would exhaust it
2/ Aborted the query if its cost was greater than the threshold

Initially there was quite a noticeable performance penalty with it
enabled - but as the guy working on it (me) redid bits and pieces then
penalty decreased massively. Note that in all cases, disabling the
feature meant there was no penalty.

The latest variant of the code is around in the Bizgres repository
(src/backend/utils/resscheduler I think) - some bits might be worth
looking at!

Best wishes

Mark

P.s : I'm not working for Greenplum now.

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

[pgsql-es-ayuda] retornar varias filas de un pl pgsql

HOLa !!
soy nuevo en lenguaje de bdatos, alguien que me ayude con una funcion que devuelva mas de un registro de una tabla, he intentado con record, refcursores y ninguna me sale , a lo mas tiro una fila pero tengo 8 filas, registros tuplas, en mi tabla prestadora, como lo hago??' tengo esta funcion q devuelve una sola fila.

CREATE OR REPLACE FUNCTION p5()
RETURNS record AS
$BODY$DECLARE
algo RECORD;
BEGIN

SELECT INTO algo * FROM prestadora;

return algo;
END;$BODY$
LANGUAGE 'plpgsql'


ahora como lo hago para que la funcion me devuelva el SELECT * FROM prestadora; completo??
de antemano gracias!!

Re: [ADMIN] client_encoding error on load


On Sun, Aug 3, 2008 at 9:38 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Andrew Goodnough" <agoodno@gmail.com> writes:
> I'm using these commands to perform a dump and load.
> pg_dump -c lakevie_typo | gzip > $HOME/backups/typo_$DATE.sql.gz
> gzip < $HOME/backups/typo_$DATE.sql.gz |psql -d lakevie_typobak -f -

Surely the second step must start with gunzip?

                       regards, tom lane

 
Yeah, that's gotta be it.  Dumb error, thanks.

Andy


Re: [ADMIN] client_encoding error on load

It will better you export and import through network by using following command.
psql -U < schemaname >  < databasename>   --schema=schemaname | psql  -U postgres  -h < IP adddress of system where you are importing data> <database name>
----- Original Message -----
Sent: Monday, August 04, 2008 7:29 AM
Subject: [ADMIN] client_encoding error on load

I'm using these commands to perform a dump and load.

pg_dump -c lakevie_typo | gzip > $HOME/backups/typo_$DATE.sql.gz
gzip < $HOME/backups/typo_$DATE.sql.gz |psql -d lakevie_typobak -f -

The dump is fine but the load only works if I first extract the sql, then run it.  Running it using the pipe to psql, I get:

psql:<stdin>:71: ERROR:  invalid byte sequence for encoding "UTF8": 0x8b
HINT:  This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

yet, doing a 'psql -l' shows this database to be UTF-8.  And the dump file says:

SET client_encoding = 'UTF8';


My goal is to get the two line dump/load working so I don't have any manual steps and sql files laying around.  Any ideas?

Andy

Re: [HACKERS] small bug in hlCover

On Mon, 2008-08-04 at 00:36 -0300, Euler Taveira de Oliveira wrote:
> Sushant Sinha escreveu:
> > I think there is a slight bug in hlCover function in wparser_def.c
> >
> The bug is not in the hlCover. In prsd_headline, if we didn't find a
> suitable bestlen (i.e. >= 0), than it includes up to document length or
> *maxWords* (here is the bug). I'm attaching a small patch that fixes it
> and some comment typos. Please apply it to 8_3_STABLE too.

Well hlCover purpose is to find a cover and for the document '1 2 3 4 5
6 7 8 9 10' and the query '1'::tsquery, a cover exists. So it should
point it out.

On my source I see that prsd_headline marks only min_words which seems
like the right thing to do.

-Sushant.

>
> euler=# select ts_headline('1 2 3 4 5 6 7 8 9 10','1'::tsquery,
> 'MinWords=5');
> ts_headline
> -----------------------------
> <b>1</b> 2 3 4 5 6 7 8 9 10
> (1 registro)
>
> euler=# select ts_headline('1 2 3 4 5 6 7 8 9 10','1'::tsquery);
> ts_headline
> -----------------------------
> <b>1</b> 2 3 4 5 6 7 8 9 10
> (1 registro)
>
>


--
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] Instructions for adding new catalog

"Gustavo Tonini" <gustavotonini@gmail.com> writes:
> Well, just for documenting the process...
> Adding new postgres catalog in 2 little steps:

> 1)Write catalog header file and save it into "src/include/catalog"
> directory. Hint: copy format from other catalog headers.
> 2)Add your header file name to variable POSTGRES_BKI_SRCS in file
> "src/backend/catalog/Makefile"

As long as we're documenting ...

* Documenting a new catalog in catalogs.sgml is not considered optional.
* Most likely, your catalog needs some indexes, which should be declared
in catalog/indexing.h.
* Of course, the reason you are defining a new system catalog is that
the C code is going to know about it. So there is a whole lot of
other stuff you probably need to write: object insertion code,
object deletion code, lookup code (maybe a new syscache or two).
Traditionally the lowest-level insertion/deletion code goes into
catalog/pg_yourcatalog.c, while slightly higher-level code such as
the implementation of new utility commands to manage this new kind
of object will go elsewhere.

That's before you get to any actual new functionality...

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] Mini improvement: statement_cost_limit

On Sunday 03 August 2008 15:12:22 Simon Riggs wrote:
> On Sun, 2008-08-03 at 00:44 -0700, daveg wrote:
> > On Sat, Aug 02, 2008 at 09:30:08PM +0200, Hans-Jürgen Schönig wrote:
> > > On Aug 2, 2008, at 8:38 PM, Tom Lane wrote:
> > > >Andrew Dunstan <andrew@dunslane.net> writes:
> > > >>Hans-Jürgen Schönig wrote:
> > > >>>i introduced a GUC called statement_cost_limit which can be used to
> > > >>>error out if a statement is expected to be too expensive.
> > > >>
> > > >>You clearly have far more faith in the cost estimates than I do.
> > > >
> > > >Wasn't this exact proposal discussed and rejected awhile back?
> > >
> > > i don't remember precisely.
> > > i have seen it on simon's wiki page and it is something which would
> > > have been useful in some cases in the past.
>
> I still support it. Regrettably, many SQL developers introduce product
> joins and other unintentional errors. Why let problem queries through?
> Security-wise they're great Denial of Service attacks, bringing the
> server to its knees better than most ways I know, in conjunction with a
> nice hefty work_mem setting. 27 table product joins: memory, CPU, I/O
> and diskspace resources used all in a simple killer query.
>

ISTR that what ended up killing the enthusiasm for this was that most people
realized that this GUC was just a poor tool to take a stab at solving other
problems (ie. rate limiting cpu for queries).

> If anybody thinks costs are inaccurate, don't use it. Or better still
> improve the cost models. It isn't any harder or easier to find a useful
> value than it is to use statement_timeout. What's the difference between
> picking an arbitrary time and an arbitrary cost? You need to alter the
> value according to people's complaints in both cases.
>

I think the original argument for statement_timeout was that long running
queries were known to cause have wrt vacuum strategies (remember, that one
has been in the back end a long time). ISTR some recent threds on -hackers
questioning whether statement_timeout should be eliminated itself.

> > I think a variation on this could be very useful in development and test
> > environments. Suppose it raised a warning or notice if the cost was over
> > the limit. Then one could set a limit of a few million on the development
> > and test servers and developers would at least have a clue that they
> > needed to look at explain for that query. As it is now, one can exhort
> > them to run explain, but it has no effect. Instead we later see queries
> > killed by a 24 hour timeout with estimated costs ranging from "until they
> > unplug the machine and dump it" to "until the sun turns into a red
> > giant".
>
> Great argument. So that's 4 in favour at least.
>

Not such a great argument. Cost models on development servers can and often
are quite different from those on production, so you might be putting an
artifical limit on top of your developers.

> A compromise would be to have log_min_statement_cost (or
> warn_min_statement_cost) which will at least help find these problems in
> testing before we put things live, but that still won't help with
> production issues.
>
> Another alternative would be to have a plugin that can examine the plan
> immediately after planner executes, so you can implement this yourself,
> plus some other possibilities.
>

I still think it is worth revisiting what problems people are trying to solve,
and see if there are better tools they can be given to solve them. Barring
that, I suppose a crude solution is better than nothing, though I fear people
might point at the crude solution as a good enough solution to justify not
working on better solutions.

--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL

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

Re: [pgsql-es-ayuda] Insertar



2008/8/3 Jaime Casanova <jcasanov@systemguards.com.ec>
On Sun, Aug 3, 2008 at 2:16 PM, Luis Martínez
<luisedgardomartinezlinares@gmail.com> wrote:
> Buenas amigos
> Mi pregunta es ¿Puedo insertar valores du na tabla en BD1 a Otra tabla de
> BD2? si es asi como lo hago gracias por la atencion

si las dos bases de datos son postgres, podrias probar plproxy


--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Guayaquil - Ecuador
Cel. (593) 87171157

Como es eso del plproxy,  y lo de las conexiones dblink
--
Ing. Luis E Martínez L
telf 0412-962-46-13

Re: [pgsql-es-ayuda] Insertar

On Sun, Aug 3, 2008 at 2:16 PM, Luis Martínez
<luisedgardomartinezlinares@gmail.com> wrote:
> Buenas amigos
> Mi pregunta es ¿Puedo insertar valores du na tabla en BD1 a Otra tabla de
> BD2? si es asi como lo hago gracias por la atencion

si las dos bases de datos son postgres, podrias probar plproxy


--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Guayaquil - Ecuador
Cel. (593) 87171157
--
TIP 10: no uses HTML en tu pregunta, seguro que quien responda no podrá leerlo

Re: [GENERAL] pgsql-general@postgresql.org.

Hi.

Sorry, it was not included in release.
please see,
http://winpg.jp/~saito/pg_work/OSSP_win32/

Regards,
Hiroshi Saito

>Hi all,
>
>I installed postgresql-8.3.3-1 for win2000 with UUID-OSSP. Following
>the documentation I issued this query:
>
>SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
>
>but the DB returns with this error message:
>
>ERROR: function uuid_ns_url() does not exist
>SQL state: 42883
>Hint: No function matches the given name and argument types. You might
>need to add explicit type casts.
>Character: 25
>
>Any hint to use UUID within my database tirggers?
>
>Thank you,
>Laci
>
>
>--
>Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-general

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

Re: [pgsql-de-allgemein] In Funktion prüfen ob Zeile existiert

Oliver Baer <oliver.baer@presswatch.de> wrote:

> [...]
> Ich stelle mir einfach eine IF abfrage vor:

> IF insert schlägt fehl THEN update ...

Aufgrund einer Abneigung gegen Exceptions schreibe ich so
etwas meist in der Form:

| UPDATE Table SET Something = 'something' WHERE ID = 'id';
| IF NOT FOUND THEN
| INSERT INTO Table (ID, Something) VALUES ('id', 'something');
| END IF;

Tim

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

Re: [GENERAL] uuid

On Aug 3, 2008, at 1:18 PM, grafl@datatrans.hu wrote:
> ERROR: function uuid_ns_url() does not exist

Remember to install the functions in your database using the SQL file
in the contrib/uuid-ossp directory, uuid-ossp.sql.

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

UUID in windows was Re: [GENERAL] pgsql-general@postgresql.org.

Pretty sure the uuid stuff only works in non-windows OSes.

Oh, and next time, use a more descriptive subject line for better /
quicker responses.

On Sun, Aug 3, 2008 at 2:18 PM, <grafl@datatrans.hu> wrote:
> Hi all,
>
> I installed postgresql-8.3.3-1 for win2000 with UUID-OSSP. Following the
> documentation I issued this query:
>
> SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
>
> but the DB returns with this error message:
>
> ERROR: function uuid_ns_url() does not exist
> SQL state: 42883
> Hint: No function matches the given name and argument types. You might need
> to add explicit type casts.
> Character: 25
>
> Any hint to use UUID within my database tirggers?
>
> Thank you,
> Laci
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

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

Re: [pgsql-de-allgemein] In Funktion prüfen ob Zeile existiert

2008/7/31, Oliver Baer <oliver.baer@presswatch.de>:
> Hallo,
>
> ich habe hier einen teil einer Postgresfunktion welche eine Tabelle updated.
>
> ...
> LOOP
> -- RAISE NOTICE 'notify_id %', asset_notify.notify_id;
> -- RAISE NOTICE 'asset_id %', NEW.asset_id;
> -- RAISE NOTICE 'label_id %', asset_notify.label_id;
> INSERT INTO asset.asset_labels (label_id, asset_id, state,
> login_id) values (asset_notify.label_id, NEW.asset_id, -2,
> asset_notify.login_id);
> END LOOP;
> ...
>
> Das problem welches ich gerade habe ist folgendes.
>
> Es kann sein das mit das der insert auf die tabelle fehlschlägt weil
> dort schon etwas drinsteht (unique auf asset_id, label_id). Das würde
> ich gerne abfangen, das heisst wenn der insert fehlschlägt soll er ein
> update machen.
>
> Leider kenne ich mit Funktionen in Postgres nicht so gut aus, vielleicht
> hilft mir ja hier jemand auf die sprünge...
>
> Ich stelle mir einfach eine IF abfrage vor:
>
> IF insert schlägt fehl THEN update ...
>
> Danke schonmal,

Mir würde da als erstes Exceptions einfallen:
http://www.postgresql.org/docs/8.3/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

Vielleicht hilft Dir das ja schon mal weiter.

>
> Oli
>
Robert

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

[HACKERS] unnecessary code in_bt_split

I found that _bt_split function calls PageGetTempPage, but next call is
_bt_page_init which clear all contents anyway. Is there any reason to call
PageGetTempPage instead of palloc?

Original code:

00796 leftpage = PageGetTempPage(origpage, sizeof(BTPageOpaqueData));
00797 rightpage = BufferGetPage(rbuf);
00798
00799 _bt_pageinit(leftpage, BufferGetPageSize(buf));

Suggested code:

00796 leftpage = palloc(PageGetSize(origpage));
00797 rightpage = BufferGetPage(rbuf);
00798
00799 _bt_pageinit(leftpage, BufferGetPageSize(buf));


Any idea?

thanks Zdenek

--
Zdenek Kotala Sun Microsystems
Prague, Czech Republic http://sun.com/postgresql


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

Re: [pgsql-es-ayuda] Insertar

On Sun, Aug 3, 2008 at 3:16 PM, Luis Martínez
<luisedgardomartinezlinares@gmail.com> wrote:
> Buenas amigos
> Mi pregunta es ¿Puedo insertar valores du na tabla en BD1 a Otra tabla de
> BD2? si es asi como lo hago gracias por la atencion

Hola, dblink soluciona tu pregunta. La documentación:

http://www.postgresql.org/docs/current/static/dblink.html

Alguien ya pregunto esto y en este post se le contesto:

http://archives.postgresql.org/pgsql-es-ayuda/2008-05/msg00612.php

--
Marco Antonio Frias Butrón
Slackware Linux User
Linux Registered User #356229
--
TIP 9: visita nuestro canal de IRC #postgresql-es en irc.freenode.net

Re: [HACKERS] Mini improvement: statement_cost_limit

On Sun, 2008-08-03 at 22:09 +0200, Hans-Jürgen Schönig wrote:

> > Another alternative would be to have a plugin that can examine the
> > plan
> > immediately after planner executes, so you can implement this
> > yourself,
> > plus some other possibilities.
> >

> this would be really fancy.
> how could a plugin like that look like?

Hmm...thinks: exactly like the existing planner_hook().

So, rewrite this as a planner hook and submit as a contrib module.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support


--
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: Add a separate TRUNCATE permission

On Tue, 2008-07-29 at 09:03 -0400, Stephen Frost wrote:
> * Peter Eisentraut (peter_e@gmx.net) wrote:
> > Am Tuesday, 29. July 2008 schrieb Stephen Frost:
> > > I'd certainly like to see a truncate permission, I wrote a patch for it
> > > myself back in January of 2006. That thread starts here:
> > >
> > > http://archives.postgresql.org/pgsql-patches/2006-01/msg00028.php
> > >
> > > I think someone else submitted a patch for it last year too, actually.

It was raised in January and rejected again then. Glad to see it raised
again here. I believe Tom's previous concerns about allowing truncate
permissions were related to the potentially increased number of truncate
commands this would cause and the need to tune invalidation messages.
That's done now.

> > Well, that certainly indicates some demand.
> >
> > I think we should worry about adding more bits when we need them. It's
> > certainly possible to add more bits, so it is not like we need to save the
> > ones we have forever.
>
> I would agree with this. Others?

I've no problem with running out of bits. At this rate, we have enough
some for some years yet. But I don't see too many additional permissions
coming along anyhow.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support


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

[GENERAL] pgsql-general@postgresql.org.

Hi all,

I installed postgresql-8.3.3-1 for win2000 with UUID-OSSP. Following
the documentation I issued this query:

SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');

but the DB returns with this error message:

ERROR: function uuid_ns_url() does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might
need to add explicit type casts.
Character: 25

Any hint to use UUID within my database tirggers?

Thank you,
Laci


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

Re: [HACKERS] Mini improvement: statement_cost_limit

hello ...


>
> I still support it. Regrettably, many SQL developers introduce product
> joins and other unintentional errors. Why let problem queries through?


i think the killer is that we don't have to wait until the query dies
with a statement_timeout.
it is ways more elegant to kill things before they have already eaten
too many cycles.
one thing which is important as well: statement_cost_limit does not
kill queries which have just been waiting for a lock.
this makes things slightly more predictable.


> Security-wise they're great Denial of Service attacks, bringing the
> server to its knees better than most ways I know, in conjunction
> with a
> nice hefty work_mem setting. 27 table product joins: memory, CPU, I/O
> and diskspace resources used all in a simple killer query.
>


i am not too concerned about DNS, i have to admit.
i would rather see it as a way to make developers do better things.


> If anybody thinks costs are inaccurate, don't use it. Or better still
> improve the cost models. It isn't any harder or easier to find a
> useful
> value than it is to use statement_timeout. What's the difference
> between
> picking an arbitrary time and an arbitrary cost? You need to alter the
> value according to people's complaints in both cases.


the cost model is good enough to see if something is good or bad.
this is basically all we want to do here --- killing all evil.


> *snip*


>
>
> A compromise would be to have log_min_statement_cost (or
> warn_min_statement_cost) which will at least help find these
> problems in
> testing before we put things live, but that still won't help with
> production issues.
>


definitely. a good idea as well - but people will hardly read it, i
guess :(.


> Another alternative would be to have a plugin that can examine the
> plan
> immediately after planner executes, so you can implement this
> yourself,
> plus some other possibilities.
>


this would be really fancy.
how could a plugin like that look like?

hans

--
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt
Web: www.postgresql-support.de


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

[pgsql-es-ayuda] Insertar

Buenas amigos
Mi pregunta es ¿Puedo insertar valores du na tabla en BD1 a Otra tabla de BD2? si es asi como lo hago gracias por la atencion
--
Ing. Luis E Martínez L
telf 0412-962-46-13

Re: [HACKERS] small bug in hlCover

Has any one noticed this?

-Sushant.

On Wed, 2008-07-16 at 23:01 -0400, Sushant Sinha wrote:
> I think there is a slight bug in hlCover function in wparser_def.c
>
> If there is only one query item and that is the first word in the text,
> then hlCover does not returns any cover. This is evident in this example
> when ts_headline only generates the min_words:
>
> testdb=# select ts_headline('1 2 3 4 5 6 7 8 9 10','1'::tsquery,
> 'MinWords=5');
> ts_headline
> ------------------
> <b>1</b> 2 3 4 5
> (1 row)
>
> The problem is that *q is initialized to 0 which is a legitimate value
> for a cover. So I have attached a patch that fixes it and after applying
> the patch here is the result.
>
> testdb=# select ts_headline('1 2 3 4 5 6 7 8 9 10','1'::tsquery,
> 'MinWords=5');
> ts_headline
> -----------------------------
> <b>1</b> 2 3 4 5 6 7 8 9 10
> (1 row)
>
> -Sushant.


--
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] Mini improvement: statement_cost_limit

On Sun, 2008-08-03 at 00:44 -0700, daveg wrote:
> On Sat, Aug 02, 2008 at 09:30:08PM +0200, Hans-Jürgen Schönig wrote:
> > On Aug 2, 2008, at 8:38 PM, Tom Lane wrote:
> >
> > >Andrew Dunstan <andrew@dunslane.net> writes:
> > >>Hans-Jürgen Schönig wrote:
> > >>>i introduced a GUC called statement_cost_limit which can be used to
> > >>>error out if a statement is expected to be too expensive.
> > >
> > >>You clearly have far more faith in the cost estimates than I do.
> > >
> > >Wasn't this exact proposal discussed and rejected awhile back?
> > >
> > i don't remember precisely.
> > i have seen it on simon's wiki page and it is something which would
> > have been useful in some cases in the past.

I still support it. Regrettably, many SQL developers introduce product
joins and other unintentional errors. Why let problem queries through?
Security-wise they're great Denial of Service attacks, bringing the
server to its knees better than most ways I know, in conjunction with a
nice hefty work_mem setting. 27 table product joins: memory, CPU, I/O
and diskspace resources used all in a simple killer query.

If anybody thinks costs are inaccurate, don't use it. Or better still
improve the cost models. It isn't any harder or easier to find a useful
value than it is to use statement_timeout. What's the difference between
picking an arbitrary time and an arbitrary cost? You need to alter the
value according to people's complaints in both cases.

> I think a variation on this could be very useful in development and test
> environments. Suppose it raised a warning or notice if the cost was over
> the limit. Then one could set a limit of a few million on the development
> and test servers and developers would at least have a clue that they needed
> to look at explain for that query. As it is now, one can exhort them to
> run explain, but it has no effect. Instead we later see queries killed
> by a 24 hour timeout with estimated costs ranging from "until they unplug
> the machine and dump it" to "until the sun turns into a red giant".

Great argument. So that's 4 in favour at least.

A compromise would be to have log_min_statement_cost (or
warn_min_statement_cost) which will at least help find these problems in
testing before we put things live, but that still won't help with
production issues.

Another alternative would be to have a plugin that can examine the plan
immediately after planner executes, so you can implement this yourself,
plus some other possibilities.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support


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

[COMMITTERS] pgsql: Make GROUP BY work properly for datatypes that only support

Log Message:
-----------
Make GROUP BY work properly for datatypes that only support hashing and not
sorting. The infrastructure for this was all in place already; it's only
necessary to fix the planner to not assume that sorting is always an available
option.

Modified Files:
--------------
pgsql/src/backend/optimizer/plan:
planmain.c (r1.107 -> r1.108)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/planmain.c?r1=1.107&r2=1.108)
planner.c (r1.236 -> r1.237)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/planner.c?r1=1.236&r2=1.237)
pgsql/src/backend/parser:
parse_clause.c (r1.172 -> r1.173)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_clause.c?r1=1.172&r2=1.173)

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

Re: [pgsql-es-ayuda] Resultado de now()

On Sun, Aug 3, 2008 at 10:34 AM, luis alfonso cañas
<lucho.canas@gmail.com> wrote:
> Hola a todos.
>
> Requiero el conocimiento de ustedes para deteminar la causa por la cual la
> funcion now() me devuelve siempre la misma hora.
>
yo creo que lo que realmente necesitas es leer el manual:
http://www.postgresql.org/docs/8.3/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT


Todas estas devuelven valores basandose en la fecha de *inicio de la
transaccion* actual:
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
CURRENT_TIME(precision)
CURRENT_TIMESTAMP(precision)
LOCALTIME
LOCALTIMESTAMP
LOCALTIME(precision)
LOCALTIMESTAMP(precision)
now()
transaction_timestamp()

Esta devuelve valores basandose en la fecha de *inicio de la sentencia* actual
statement_timestamp()

Estas devuelven las fechas reales actuales (según el reloj de tu
maquina me parece):
clock_timestamp()
timeofday()

Para lo que tu quieres deberias usar statement_timestamp() o clock_timestamp()

--
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Guayaquil - Ecuador
Cel. (593) 87171157
--
TIP 7: no olvides aumentar la configuración del "free space map"

Re: [GENERAL] Advice on implementing counters in postgreSQL

On Sun, Aug 3, 2008 at 1:50 AM, Marco Bizzarri <marco.bizzarri@gmail.com> wrote:
> On Sun, Aug 3, 2008 at 1:40 AM, Berend Tober <btober@ct.metrocast.net> wrote:
>>
>>
>> The way I understand the documentation at
>>
>> "http://www.postgresql.org/docs/8.3/static/transaction-iso.html"
>>
>> and
>>
>> 'http://www.postgresql.org/docs/current/static/explicit-locking.html',
>>
>> you should not have to use the serial isolation level.
>>
>> I would define the counter table so as to hold the last-used value, rather
>> that the "next" value, and then do the UPDATE first.
>>
>> As a consequence, assuming all this happens within a transaction of course,
>> the SELECT FOR UPDATE syntax is not required either because the UPDATE will
>> grab a lock on the row and block other updates until the transaction is
>> finished. That is, concurrency is protected and you don't have to restart
>> any transactions because subsequent transactions will just wait until the
>> first one finishes due to nature of the lock automatically acquired by the
>> initial UPDATE statement.
>>
>
> Yes, I'm considering moving away from serializable; the problem is
> that I have to explore all the implications of this on my code. Up to
> now, I wrote considering a serializable level, so I think I should do
> quite a review to be sure about it.

A fairly simple test shows that you can do this in read committed:

S1: # show transaction_isolation;
read committed

(setup a table for the value)
# create table t (i int);
# insert into t values (5);


S1: # begin;
S1: # update t set i=i+1;
S2: # update t set i=i+1;
(S2 now waits for S1)
S1: # select i from t;
6
S1: # commit;
(S2 now can continue...)
S2: # select i from t;
7
S2: # commit;

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

[pgsql-es-ayuda] Resultado de now()

Hola a todos.
 
Requiero el conocimiento de ustedes para deteminar la causa por la cual la funcion now() me devuelve siempre la misma hora.
 
Tengo una funcion que su ejecucion toma varios minutos, por que efectua muchas actividades.
 
Antes de cada actividad inserto un registro en una tabla de bitacora.
Ejemplo
 
insert into bitacora (actividad,fecha) values('Actividad nro 1',now());
....
insert into bitacora (actividad,fecha) values('Actividad nro 2',now());
 
....
insert into bitacora (actividad,fecha) values('Actividad nro 3',now());
 
Al verificar  la tabla de bitacora una vez termino la ejecucion, encuentro que la todos los registros tienen el mismo dato en el campo fecha.
fecha es del tipo timestamp without time zone.
 
Por que razon sucede esto?
 
Que puedo hacer para que en cada operacion de insert en la bitacora me almacene la hora exacta?
De que otra manera podria obtener los mismos resultados?
 
Esto lo requiero para poder determinar que actividades son las que estan tomando mas tiempo y asi poderlas custumizar.
 
Muchas gracias de antemando.
 
Att
Luis Alfonso Cañas
Colombia.
 
 

[COMMITTERS] pgsql: Tighten up the sanity checks in TypeCreate(): pass-by-value types

Log Message:
-----------
Tighten up the sanity checks in TypeCreate(): pass-by-value types must have
a size that is one of the supported values, not just anything <= sizeof(Datum).
Cross-check the alignment specification against size as well.

Modified Files:
--------------
pgsql/src/backend/catalog:
pg_type.c (r1.120 -> r1.121)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/catalog/pg_type.c?r1=1.120&r2=1.121)

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

Re: [GENERAL] bytea encode performance issues

Sim Zacks <sim@compulab.co.il> writes:
> The explain of the query is:

Could we see EXPLAIN ANALYZE, not EXPLAIN? Without actual facts
to work from, any suggestions would be mere guesswork.

Also, what can you tell us about the sizes of the messageblk
strings (max and avg would be interesting)?

regards, tom lane

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

Re: [GENERAL] bytea encode performance issues

On Aug 3, 2008, at 2:36 PM, Sim Zacks wrote:

> The LIKE operator is likely the problem, but it is a critical part
> of an
> email application. Searches are done by, "Show me all emails
> containing
> the following word."
>
> I've tried using TSearch2's full text index. It made the query 50%
> faster, taking 5 minutes. This is still not even close to the less
> then
> a minute in MySQL.
>
>>
>> That LIKE operator is probably your problem. An unbounded LIKE
>> like that
>> (with a wildcard on both sides) means no index can be used, hence you
>> get a sequential scan.
>>
>> There are apparently some possibilities with the new GIN indexes (or
>> maybe even using GIST), but I haven't had an opportunity to try those
>> yet. There were some messages about just that on this list recently.
>>
>
> I don't think a functional index (or anything other then a FTI) would
> accomplish anything, being that I am doing unbounded Likes.

That's why I suggested to use a text field instead of bytea.
IIRC, You can have an index on word triplets and use tsearch. I don't
have intimate knowledge on how that works though, hopefully other
people will chime in here.

Without the need to convert each row before comparing it, and with an
appropriate index, that should significantly speed up your queries.

>> If you create an index, make sure you create a _functional_ index
>> over
>> ENCODE(messageblk, 'escape').
>>
>
> Email is binary when it contains attachments. I actually planned on
> using an ASCII encoding, but the dbmail people specifically said
> not to.
> I don't know if they were speaking from experience, or because ASCII
> sounds bad.

It shouldn't be; those attachments are MIME or UU encoded, are they not?
Don't confuse ASCII and SQLASCII. The latter accepts characters from
any encoding, which is probably what you want.

>> Since when is e-mail binary data? I don't quite see why you'd use a
>> bytea field instead of text. If your problem is character
>> encoding, then
>> just don't store that ("encode" the DB using SQLASCII).
>>
>
> As I mentioned, this is the system that came with dbmail. It runs on
> both PostGresql and MySQL, so they may have done some compatibility
> things. There are 4 statuses possible, 0,1,2,3 if you use the database
> through the software then a 99 could never appear there.

The software isn't the only client that might connect to the database.
It is usually bad practice to put data constraint logic in the client
instead of in the database. Especially since in client code there are
usually multiple sections of code that have to deal with those
constraints, which tends to result in small differences in their
handling.

Next to that, if those statuses would have a proper foreign key
constraint, it would be very easy to add labels to each status in a
way they would make a bit more sense than 0, 1, 2, 3.
I expect the label would be a sufficient foreign key by itself
though, no need for those silly numbers.

Well, there's probably not much you can do about that, being just a
user of dbMail.

>> I notice some other oddities in that query/design. Why is is_header a
>> smallint instead of a boolean? I'm assuming this is for compatibility
>> with an other database?
>>
>> Why use status IN (0, 1) instead of more descriptive keys? Is it even
>> constrained this way, or could arbitrary numbers end up as status
>> (say
>> 99) and if so, what happens to those messages?

You have a very odd way of quoting. You don't top post as such, but
you top post in context... Haven't seen that one before. Usually
people reply _below_ a section, not above it ;) It made my reply a
bit harder to write.

Alban Hertroys

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


!DSPAM:737,4895b34b243488085013917!

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

Re: [HACKERS] Parsing of pg_hba.conf and authentication inconsistencies

* Magnus Hagander (magnus@hagander.net) wrote:
> Stephen Frost wrote:
> > A little extra code in the backend is well worth fixing this foot-gun.
> > The concerns raised so far have been "who will write it?" and "what if
> > it has bugs?". Neither of these are particularly compelling arguments
> > when you've already offered to write and bug-test it (right, Magnus? :).
>
> Toms main argument has been that it would move the code *from* the
> backend and into the *postmaster*, which is much more sensitive.

erm, yes, sorry I wasn't being clear. Brain moving faster than fingers
sometimes. :)

> And yes, I've offered to write the code. I take this as an offer from
> you to bug-test it :-)

Indeed, as long as I'm bug-testing the Kerberos mappings at the same
time... ;) Seriously though, I'd be happy to review and test the code.

Thanks,

Stephen

Re: [HACKERS] Parsing of pg_hba.conf and authentication inconsistencies

* Magnus Hagander (magnus@hagander.net) wrote:
> I think it'd be reasonable to refuse starting if the config is *known
> broken* (such as containing lines that are unparseable, or that contain
> completely invalid tokens), whereas you'd start if they just contain
> things that are "probably wrong". But picking from your previous
> examples of "more advanced checks", there are lots of cases where
> things like overlapping CIDR address ranges are perfectly valid, so I
> don't think we could even throw a warning for that - unless there's a
> separate flag to enable/disable warnings for such a thing.

Agreed. Making sure the config can parse is different from parsable but
non-sensible. It's ridiculously easy to mistakenly add a line w/ a
single character on it or something equally bad when saving a file
that's being modified by hand. That's a simple check that should be
done on re-hup and the broken config shouldn't be put in place.

I certainly agree that we should *also* have a way to just check the
config, so that can be built into init scripts and whatnot. I don't
think having one precludes having the other, and I'm pretty confident we
could find a way to not duplicate the code and have things be clean.

Thanks,

Stephen

Re: [HACKERS] Parsing of pg_hba.conf and authentication inconsistencies

Stephen Frost wrote:
> * Magnus Hagander (magnus@hagander.net) wrote:
>> For pg_hba.conf, I don't see that as a very big problem, really. It
>> doesn't (and shouldn't) modify any "external" variables, so it should be
>> as simple as parsing the new file into a completely separate
>> list-of-structs and only if it's all correct switch the main pointer
>> (and free the old struct).
>
> I'm in agreement with this approach. Allowing a config which won't
> parse properly to completely break access to a running database is
> terrible. It just doesn't come across to me as being all that difficult
> or complex code for pg_hba.conf.

That's my thoughts as well, which may be off of course ;-)


>> Yes, I still think we should do the "simple parsing" step at HUP time.
>> That doesn't mean that it wouldn't be a good idea to have one of these
>> check-config options that can look for conflicting options *as well*, of
>> course. But I'm getting the feeling I'm on the losing side of the debate
>> here...
>
> A little extra code in the backend is well worth fixing this foot-gun.
> The concerns raised so far have been "who will write it?" and "what if
> it has bugs?". Neither of these are particularly compelling arguments
> when you've already offered to write and bug-test it (right, Magnus? :).

Toms main argument has been that it would move the code *from* the
backend and into the *postmaster*, which is much more sensitive.

And yes, I've offered to write the code. I take this as an offer from
you to bug-test it :-)

//Magnus

--
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] Parsing of pg_hba.conf and authentication inconsistencies

* Magnus Hagander (magnus@hagander.net) wrote:
> For pg_hba.conf, I don't see that as a very big problem, really. It
> doesn't (and shouldn't) modify any "external" variables, so it should be
> as simple as parsing the new file into a completely separate
> list-of-structs and only if it's all correct switch the main pointer
> (and free the old struct).

I'm in agreement with this approach. Allowing a config which won't
parse properly to completely break access to a running database is
terrible. It just doesn't come across to me as being all that difficult
or complex code for pg_hba.conf.

> Yes, I still think we should do the "simple parsing" step at HUP time.
> That doesn't mean that it wouldn't be a good idea to have one of these
> check-config options that can look for conflicting options *as well*, of
> course. But I'm getting the feeling I'm on the losing side of the debate
> here...

A little extra code in the backend is well worth fixing this foot-gun.
The concerns raised so far have been "who will write it?" and "what if
it has bugs?". Neither of these are particularly compelling arguments
when you've already offered to write and bug-test it (right, Magnus? :).

Thanks,

Stephen

Re: [GENERAL] bytea encode performance issues

The LIKE operator is likely the problem, but it is a critical part of an
email application. Searches are done by, "Show me all emails containing
the following word."

I've tried using TSearch2's full text index. It made the query 50%
faster, taking 5 minutes. This is still not even close to the less then
a minute in MySQL.

>
> That LIKE operator is probably your problem. An unbounded LIKE like that
> (with a wildcard on both sides) means no index can be used, hence you
> get a sequential scan.
>
> There are apparently some possibilities with the new GIN indexes (or
> maybe even using GIST), but I haven't had an opportunity to try those
> yet. There were some messages about just that on this list recently.
>

I don't think a functional index (or anything other then a FTI) would
accomplish anything, being that I am doing unbounded Likes.

> If you create an index, make sure you create a _functional_ index over
> ENCODE(messageblk, 'escape').
>

Email is binary when it contains attachments. I actually planned on
using an ASCII encoding, but the dbmail people specifically said not to.
I don't know if they were speaking from experience, or because ASCII
sounds bad.

> Since when is e-mail binary data? I don't quite see why you'd use a
> bytea field instead of text. If your problem is character encoding, then
> just don't store that ("encode" the DB using SQLASCII).
>

As I mentioned, this is the system that came with dbmail. It runs on
both PostGresql and MySQL, so they may have done some compatibility
things. There are 4 statuses possible, 0,1,2,3 if you use the database
through the software then a 99 could never appear there.

>
>
> I notice some other oddities in that query/design. Why is is_header a
> smallint instead of a boolean? I'm assuming this is for compatibility
> with an other database?
>
> Why use status IN (0, 1) instead of more descriptive keys? Is it even
> constrained this way, or could arbitrary numbers end up as status (say
> 99) and if so, what happens to those messages?
>
> Alban Hertroys
>
> --
> If you can't see the forest for the trees,
> cut the trees and you'll see there is no forest.
>
>
> !DSPAM:824,48958f30243481673380013!
>
>

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

Re: [GENERAL] bytea encode performance issues

On Aug 3, 2008, at 12:12 PM, Sim Zacks wrote:

> This is the query that is used (I know it is not as efficient as it
> could be, but this is the query it comes with):
>
> SELECT m.message_idnr,k.messageblk FROM dbmail_messageblks k JOIN
> dbmail_physmessage p ON k.physmessage_id = p.id JOIN dbmail_messages m
> ON p.id = m.physmessage_id WHERE mailbox_idnr = 8 AND status IN (0,1 )
> AND k.is_header = '0' GROUP BY m.message_idnr,k.messageblk HAVING
> ENCODE(k.messageblk::bytea,'escape') LIKE '%John%'

That LIKE operator is probably your problem. An unbounded LIKE like
that (with a wildcard on both sides) means no index can be used,
hence you get a sequential scan.

There are apparently some possibilities with the new GIN indexes (or
maybe even using GIST), but I haven't had an opportunity to try those
yet. There were some messages about just that on this list recently.

If you create an index, make sure you create a _functional_ index
over ENCODE(messageblk, 'escape').

> The messageblk field is a bytea in postgresql and a longblob in
> mysql.
> The only difference in the query is the MySQL does not need the encode
> function.

Since when is e-mail binary data? I don't quite see why you'd use a
bytea field instead of text. If your problem is character encoding,
then just don't store that ("encode" the DB using SQLASCII).

> Can someone make a suggestion for tuning the database?

An explain analyze would have been a bit more useful, but the biggest
issue is probably the seqscan.

> The explain of the query is:
> "HashAggregate (cost=43648.11..43648.85 rows=74 width=753)"
> " -> Nested Loop (cost=42999.83..43647.74 rows=74 width=753)"
> " -> Merge Join (cost=42999.83..43043.35 rows=74 width=769)"
> " Merge Cond: (k.physmessage_id = m.physmessage_id)"
> " -> Sort (cost=39264.12..39267.59 rows=1388
> width=753)"
> " Sort Key: k.physmessage_id"
> " -> Seq Scan on dbmail_messageblks k
> (cost=0.00..39191.68 rows=1388 width=753)"
> " Filter: ((is_header = 0::smallint) AND
> (encode(messageblk, 'escape'::text) ~~ '%John%'::text))"

Here is your problem, a sequential scan over a presumably large
table. It's either caused by the LIKE expression or by the lack of a
functional index on messageblk, or both.

If you change the type of the messageblk field to text you won't need
a functional index anymore (although that only saves time on index
creation and inserts/updates).

> " -> Sort (cost=3735.71..3754.59 rows=7552 width=16)"
> " Sort Key: m.physmessage_id"
> " -> Bitmap Heap Scan on dbmail_messages m
> (cost=385.98..3249.26 rows=7552 width=16)"
> " Recheck Cond: ((mailbox_idnr = 8) AND
> (status
> = ANY ('{0,1}'::integer[])))"
> " -> Bitmap Index Scan on dbmail_messages_8
> (cost=0.00..384.10 rows=7552 width=0)"
> " Index Cond: ((mailbox_idnr = 8) AND
> (status = ANY ('{0,1}'::integer[])))"
> " -> Index Scan using dbmail_physmessage_pkey on
> dbmail_physmessage p (cost=0.00..8.15 rows=1 width=8)"
> " Index Cond: (k.physmessage_id = p.id)"


I notice some other oddities in that query/design. Why is is_header a
smallint instead of a boolean? I'm assuming this is for compatibility
with an other database?

Why use status IN (0, 1) instead of more descriptive keys? Is it even
constrained this way, or could arbitrary numbers end up as status
(say 99) and if so, what happens to those messages?

Alban Hertroys

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


!DSPAM:737,48958f34243483105918576!

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

Re: [HACKERS] Parsing of pg_hba.conf and authentication inconsistencies

"Tom Lane" <tgl@sss.pgh.pa.us> writes:

> Robert Treat <xzilla@users.sourceforge.net> writes:
>> Certainly there isn't any reason to allow a reload of a file that is just
>> going to break things when the first connection happens. For that matter,
>> why would we ever not want to parse it at HUP time rather than connect time?
>
> Two or three reasons why not were already mentioned upthread, but for
> the stubborn, here's another one: are you volunteering to write the code
> that backs out the config-file reload after the checks have determined
> it was bad? Given the amount of pain we suffered trying to make GUC do
> something similar, any sane person would run screaming from the
> prospect.

Wouldn't that be *easier* if we do more parsing in the postmaster instead of
in the backends as Magnus suggested? Then it could build a new set of
structures and if there are any errors just throw them out before replacing
the old ones.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's Slony Replication support!

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

[GENERAL] bytea encode performance issues

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am using postgresql 8.2.7 on gentoo for my dbmail backend.
I am also testing it on mysql 5.

I am trying to figure out if I need to tune my database configuration or
if querying a bytea field is just not practical in postgresql.

Searching with the mysql database takes under a minute and with the
postgresql database it takes approximately 10. It gets better when I fix
up the query a little, such as removing the group by and having and
including the clause as part of the where, but not anywhere close to the
mysql level.

This is the query that is used (I know it is not as efficient as it
could be, but this is the query it comes with):

SELECT m.message_idnr,k.messageblk FROM dbmail_messageblks k JOIN
dbmail_physmessage p ON k.physmessage_id = p.id JOIN dbmail_messages m
ON p.id = m.physmessage_id WHERE mailbox_idnr = 8 AND status IN (0,1 )
AND k.is_header = '0' GROUP BY m.message_idnr,k.messageblk HAVING
ENCODE(k.messageblk::bytea,'escape') LIKE '%John%'

The messageblk field is a bytea in postgresql and a longblob in mysql.
The only difference in the query is the MySQL does not need the encode
function.

I have plugged the query into the psql and mysql command line
applications, so I could evaluate the query without the application.

The database is using autovacuum and the estimated rows and the actual
rows are almost the same, so I assume it is working. There are 310266
rows in the dbmail_messageblks table.

Can someone make a suggestion for tuning the database?

The explain of the query is:
"HashAggregate (cost=43648.11..43648.85 rows=74 width=753)"
" -> Nested Loop (cost=42999.83..43647.74 rows=74 width=753)"
" -> Merge Join (cost=42999.83..43043.35 rows=74 width=769)"
" Merge Cond: (k.physmessage_id = m.physmessage_id)"
" -> Sort (cost=39264.12..39267.59 rows=1388 width=753)"
" Sort Key: k.physmessage_id"
" -> Seq Scan on dbmail_messageblks k
(cost=0.00..39191.68 rows=1388 width=753)"
" Filter: ((is_header = 0::smallint) AND
(encode(messageblk, 'escape'::text) ~~ '%John%'::text))"
" -> Sort (cost=3735.71..3754.59 rows=7552 width=16)"
" Sort Key: m.physmessage_id"
" -> Bitmap Heap Scan on dbmail_messages m
(cost=385.98..3249.26 rows=7552 width=16)"
" Recheck Cond: ((mailbox_idnr = 8) AND (status
= ANY ('{0,1}'::integer[])))"
" -> Bitmap Index Scan on dbmail_messages_8
(cost=0.00..384.10 rows=7552 width=0)"
" Index Cond: ((mailbox_idnr = 8) AND
(status = ANY ('{0,1}'::integer[])))"
" -> Index Scan using dbmail_physmessage_pkey on
dbmail_physmessage p (cost=0.00..8.15 rows=1 width=8)"
" Index Cond: (k.physmessage_id = p.id)"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiVhHwACgkQjDX6szCBa+o6wACgwa05ZbUBL4Ef18N4JJHQ2SP1
gfwAnjIA14QktV/Qs1TrPiY+Ma+rmJht
=WOQM
-----END PGP SIGNATURE-----

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

[GENERAL] missing chunk number 0 for toast value when pg_dump??

hi, all:
I use pg_dump command to dump a specified table:
pg_dump mydb -p 5555 -Uyahoo -t mytable -D -a > /export/dump.sql

but, I got this:
-----------------------
pg_dump: SQL command failed
pg_dump: Error message from server: ERROR: missing chunk number 0 for
toast value 14319826
pg_dump: The command was: FETCH 100 FROM _pg_dump_cursor
-----------------------

the table have about 3,000,000 records, but from the dump file, I got
only 300,000 records with "INSERT INTO".

my postgresql version is :8.3.3.

thanks a lot.

regards,


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

Re: [HACKERS] Auto-explain patch

Thanks for the feedback, and sorry for my delay in replying (I was on
holiday).

> Tom Lane wrote:
>
> Comments:
>
> I do not think that you should invent a new elog level for this, and
> especially not one that is designed to send unexpected messages to the
> client. Having to kluge tab completion like that is just a signal that
> you're going to break a lot of other clients too. It seems to me that
> the right behavior for auto-explain messages is to go only to the log by
> default, which means that LOG is already a perfectly good elog level for
> auto-explain messages.

The more I thought about this, the more I thought that it was OTT to
add a new elog level just for this, so I agree it should probably just
go to the LOG elog level.

I don't agree with your reasoning on tab-completion though. I actually
think that this is a signal of a broken client. If the user sets
client_min_messages to LOG or lower, and has any of the other logging
or debugging parameters enabled, the output tramples all over the
suggested completions. I don't think the average user is interested in
log/debug output from the queries psql does internally during
tab-completion. So IMHO the tab-completion 'kludge', is still
worthwhile, regardless of the rest of the patch.


> Drop the query_string addition to PlannedStmt --- there are other ways
> you can get that string in CVS HEAD.

OK. What is the best way to get this string now? Are you referring to
debug_query_string, or is there another way?


> I don't think that planner_time
> belongs there either. It would be impossible to define a principled way
> to compare two PlannedStmts for equality with that in there. Nor do I
> see the point of doing it the way you're doing it. Why don't you just
> log the slow planning cycle immediately upon detecting it in planner()?
> I don't see that a slow planning cycle has anything necessarily to do
> with a slow execution cycle, so IMHO they ought to just get logged
> independently.

Makes sense.


> Please do not export ExplainState --- that's an internal matter for
> explain.c. Export some wrapper function with a cleaner API than
> explain_outNode, instead.
>
> regards, tom lane

OK, that's much neater.

I'll try to rework this ASAP but I understand if it's too late for
this commitfest.

Cheers, Dean.

_________________________________________________________________
Win a voice over part with Kung Fu Panda & Live Search   and   100's of Kung Fu Panda prizes to win with Live Search
http://clk.atdmt.com/UKM/go/107571439/direct/01/
--
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] Parsing of pg_hba.conf and authentication inconsistencies

Tom Lane wrote:
> Magnus Hagander <magnus@hagander.net> writes:
>>> The good way to solve this would be to have independant command line
>>> utilities which check pg_hba.conf, pg_ident.conf and postgresql.conf for
>>> errors. Then DBAs could run a check *before* restarting the server.
>
>> While clearly useful, it'd still leave the fairly large foot-gun that is
>> editing the hba file and HUPing things which can leave you with a
>> completely un-connectable database because of a small typo.
>
> That will *always* be possible, just because software is finite and
> human foolishness is not ;-).

Certainly - been bitten by that more than once. But we can make it
harder or easier to make the mistakes..


> Now, we could ameliorate it a bit given a "postgres --check-config"
> mode by having pg_ctl automatically run that mode before any start,
> restart, or reload command, and then refusing to proceed if the check
> detects any indubitable errors. On the other hand, that would leave
> us with the scenario where the checking code warns about stuff that it
> can't be sure is wrong, but then we go ahead and install the borked
> config anyway. (Nobody is going to put up with code that refuses
> to install config settings that aren't 100% clean, unless the checks
> are so weak that they miss a lot of possibly-useful warnings.)
>
> Seems a lot better to me to just train people to run the check-config
> code by hand before pulling the trigger to load the settings for real.

It's certainly easier for us, but that means a whole lot of people are
never going to do it. And initscripts might end up using it anyway,
forcing the issue.

I think it'd be reasonable to refuse starting if the config is *known
broken* (such as containing lines that are unparseable, or that contain
completely invalid tokens), whereas you'd start if they just contain
things that are "probably wrong". But picking from your previous
examples of "more advanced checks", there are lots of cases where
things like overlapping CIDR address ranges are perfectly valid, so I
don't think we could even throw a warning for that - unless there's a
separate flag to enable/disable warnings for such a thing.

//Magnus

--
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] Parsing of pg_hba.conf and authentication inconsistencies

Tom Lane wrote:
> Robert Treat <xzilla@users.sourceforge.net> writes:
>> Certainly there isn't any reason to allow a reload of a file that is just
>> going to break things when the first connection happens. For that matter,
>> why would we ever not want to parse it at HUP time rather than connect time?
>
> Two or three reasons why not were already mentioned upthread, but for
> the stubborn, here's another one: are you volunteering to write the code
> that backs out the config-file reload after the checks have determined
> it was bad? Given the amount of pain we suffered trying to make GUC do
> something similar, any sane person would run screaming from the
> prospect.

For pg_hba.conf, I don't see that as a very big problem, really. It
doesn't (and shouldn't) modify any "external" variables, so it should be
as simple as parsing the new file into a completely separate
list-of-structs and only if it's all correct switch the main pointer
(and free the old struct).

Yes, I still think we should do the "simple parsing" step at HUP time.
That doesn't mean that it wouldn't be a good idea to have one of these
check-config options that can look for conflicting options *as well*, of
course. But I'm getting the feeling I'm on the losing side of the debate
here...

//Magnus


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

Re: [pgsql-fr-generale] Petit conseil

Jonathan Ballet a écrit :
> Le Sun, 03 Aug 2008 01:43:02 +0200, Guillaume Lelarge <guillaume@lelarge.info> a écrit :
>
>> [...] En tout cas, je ne
>> connais aucun livre qui aille plus loin que la documentation officielle
>> (qui n'est pourtant pas complète).
>
> Je rebondis sur cette dernière remarque : je trouve la documentation de PostgreSQL super
> bien, claire, bien organisée, et justement plutôt "complète".
> Qu'est-ce qu'il manque dedans pour que tu la considère comme complète ?
>

Une description de la fonctionnalité HOT (dont l'absence dans la
documentation est voulue par Tom Lane, bien que critiquée par certains
développeurs), une description des Hints Bits, une liste des noeuds d'un
plan de requêtes avec une explication des algorithmes utilisés, etc. Des
informations plutôt haut niveau en fait. En lisant le code source de
PostgreSQL, on a quantité d'informations supplémentaires. Rien qu'en
lisant les fichiers README par exemple, on apprend énormément de choses.
Et je ne parle même pas du wiki de PostgreSQL.

Je suis d'accord avec toi qu'elle est très complète. J'en suis bien
conscient, je la connais plutôt bien, et les 1400 pages sont la preuve
que beaucoup de choses est documenté. Mais il y manque des éléments
importants.


--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

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

Re: [GENERAL] Advice on implementing counters in postgreSQL

On Sun, Aug 3, 2008 at 1:40 AM, Berend Tober <btober@ct.metrocast.net> wrote:
>
>
> The way I understand the documentation at
>
> "http://www.postgresql.org/docs/8.3/static/transaction-iso.html"
>
> and
>
> 'http://www.postgresql.org/docs/current/static/explicit-locking.html',
>
> you should not have to use the serial isolation level.
>
> I would define the counter table so as to hold the last-used value, rather
> that the "next" value, and then do the UPDATE first.
>
> As a consequence, assuming all this happens within a transaction of course,
> the SELECT FOR UPDATE syntax is not required either because the UPDATE will
> grab a lock on the row and block other updates until the transaction is
> finished. That is, concurrency is protected and you don't have to restart
> any transactions because subsequent transactions will just wait until the
> first one finishes due to nature of the lock automatically acquired by the
> initial UPDATE statement.
>

Yes, I'm considering moving away from serializable; the problem is
that I have to explore all the implications of this on my code. Up to
now, I wrote considering a serializable level, so I think I should do
quite a review to be sure about it.

Regards
Marco

--
Marco Bizzarri
http://iliveinpisa.blogspot.com/

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

Re: [GENERAL] Advice on implementing counters in postgreSQL

On Sat, Aug 2, 2008 at 5:11 PM, David Fetter <david@fetter.org> wrote:
> On Sat, Aug 02, 2008 at 09:23:31AM +0200, Marco Bizzarri wrote:
>> Hi all.
>>
>> I need to keep a numer of counters in my application; my counters
>> are currently stored in a table:
>>
>> name | next_value | year
>>
>> The counters must be progressive numbers with no holes in between
>> them, and they must restart from 1 every year.
>
> Here's a backward-compatible way to do this:
>
> http://www.varlena.com/GeneralBits/130.php
>
> Cheers,
> David.
> --
> David Fetter <david@fetter.org> http://fetter.org/
> Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
> Skype: davidfetter XMPP: david.fetter@gmail.com
>
> Remember to vote!
> Consider donating to Postgres: http://www.postgresql.org/about/donate
>


David, thanks for pointing me to such a complete solution.

These work both on READ-COMMITTED and SERIALIZABLE isolation levels, am I right?

Regards
Marco


--
Marco Bizzarri
http://iliveinpisa.blogspot.com/

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

Re: [HACKERS] Mini improvement: statement_cost_limit

On Sat, Aug 02, 2008 at 09:30:08PM +0200, Hans-Jürgen Schönig wrote:
> On Aug 2, 2008, at 8:38 PM, Tom Lane wrote:
>
> >Andrew Dunstan <andrew@dunslane.net> writes:
> >>Hans-Jürgen Schönig wrote:
> >>>i introduced a GUC called statement_cost_limit which can be used to
> >>>error out if a statement is expected to be too expensive.
> >
> >>You clearly have far more faith in the cost estimates than I do.
> >
> >Wasn't this exact proposal discussed and rejected awhile back?
> >
> > regards, tom lane
> >
>
>
> i don't remember precisely.
> i have seen it on simon's wiki page and it is something which would
> have been useful in some cases in the past.

I think a variation on this could be very useful in development and test
environments. Suppose it raised a warning or notice if the cost was over
the limit. Then one could set a limit of a few million on the development
and test servers and developers would at least have a clue that they needed
to look at explain for that query. As it is now, one can exhort them to
run explain, but it has no effect. Instead we later see queries killed
by a 24 hour timeout with estimated costs ranging from "until they unplug
the machine and dump it" to "until the sun turns into a red giant".

-dg

--
David Gould daveg@sonic.net 510 536 1443 510 282 0869
If simplicity worked, the world would be overrun with insects.

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

Re: [pgsql-fr-generale] Petit conseil

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkiVYYoACgkQ+cFYTXJHUVA4PQCg7w7/obP7Oe204lB5Wn9UItfI
fNgAnRPAPh9Ca6q0CoetCuWQVMbbuOrG
=dBNh
-----END PGP SIGNATURE-----
Le Sun, 03 Aug 2008 01:43:02 +0200, Guillaume Lelarge <guillaume@lelarge.info> a écrit :

> [...] En tout cas, je ne
> connais aucun livre qui aille plus loin que la documentation officielle
> (qui n'est pourtant pas complète).

Je rebondis sur cette dernière remarque : je trouve la documentation de PostgreSQL super
bien, claire, bien organisée, et justement plutôt "complète".
Qu'est-ce qu'il manque dedans pour que tu la considère comme complète ?

Merci,
Jonathan