[GENERAL] disable seqscan

2011-05-23 Thread Nick Raj
Hi,
I have build an index. When, i execute the query, it gives the result by
sequential scan, not by using my index.
I have already run vacuum analyze to collect some statistics regarding
table.

May be sequential scan is giving faster execution time than my indexing. But
i want to know how much time it would take in my indexing.
For that, i have set enable_seqscan=off in postgresql.conf. But it still
going through sequential scan. Even i tried to set for a particular session,
by set enable_seqscan=off on psql terminal.
It again going by sequential scan.

Does any one having an idea to force postgres to use index scan?

Thanks
Nick


Re: [GENERAL] disable seqscan

2011-05-23 Thread Andrew Sullivan
On Mon, May 23, 2011 at 05:31:04PM +0530, Nick Raj wrote:
 Hi,
 I have build an index. When, i execute the query, it gives the result by
 sequential scan, not by using my index.

 For that, i have set enable_seqscan=off in postgresql.conf. But it still
 going through sequential scan.

It sounds like your index can't actually be used to satisfy your
query.  Without seeing the table definition, index definition, and
query, however, it's pretty hard to give you a real answer.

A

-- 
Andrew Sullivan
a...@crankycanuck.ca

-- 
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] disable seqscan

2011-05-23 Thread Andreas Kretschmer
Andrew Sullivan a...@crankycanuck.ca wrote:

 On Mon, May 23, 2011 at 05:31:04PM +0530, Nick Raj wrote:
  Hi,
  I have build an index. When, i execute the query, it gives the result by
  sequential scan, not by using my index.
 
  For that, i have set enable_seqscan=off in postgresql.conf. But it still
  going through sequential scan.
 
 It sounds like your index can't actually be used to satisfy your
 query.  Without seeing the table definition, index definition, and
 query, however, it's pretty hard to give you a real answer.

... and the output produced by

explain analyse insert your query


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.  (Linus Torvalds)
If I was god, I would recompile penguin with --enable-fly.   (unknown)
Kaufbach, Saxony, Germany, Europe.  N 51.05082°, E 13.56889°

-- 
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] disable seqscan

2011-05-23 Thread Nick Raj
On Mon, May 23, 2011 at 5:44 PM, Andreas Kretschmer 
akretsch...@spamfence.net wrote:

 Andrew Sullivan a...@crankycanuck.ca wrote:

  On Mon, May 23, 2011 at 05:31:04PM +0530, Nick Raj wrote:
   Hi,
   I have build an index. When, i execute the query, it gives the result
 by
   sequential scan, not by using my index.
 
   For that, i have set enable_seqscan=off in postgresql.conf. But it
 still
   going through sequential scan.
 
  It sounds like your index can't actually be used to satisfy your
  query.  Without seeing the table definition, index definition, and
  query, however, it's pretty hard to give you a real answer.

 ... and the output produced by

 explain analyse insert your query

 Explain analyze of my query
 explain analyze select * from vehicle_stindex where
 ndpoint_overlap('(116.4,39.3,2008/02/11 11:11:11),(117.8,39.98,2008/02/13
 11:11:11)',stpoint);
 QUERY
 PLAN

 --
  Seq Scan on vehicle_stindex  (cost=100.00..1050870.86
 rows=698823 width=66) (actual time=3285.106..3285.106 rows=0 loops=1)
Filter: ndpoint_overlap('(116.40,39.30,2008-02-11
 11:11:11+05:30),(117.80,39.98,2008-02-13 11:11:11+05:30)'::ndpoint,
 stpoint)
  Total runtime: 3285.153 ms
 (3 rows)


 Table Defination

 Table public.vehicle_stindex
  Column  |  Type   | Modifiers
 -+-+---
  regno   | text|
  stpoint | ndpoint |
 Indexes:
 stindex gist (stpoint)

 It has 2099192 tuples.


 Index defination
 create index stindex on vehicle_stindex using gist(stpoint).


 I have defined a datatype called ndpoint. It works same as contrib/cube
 code (cube datatype).
 Query is working fine. I mean no error from query or my datatype. All are
 giving right result.

If anything more to mention, then tell me

Nick


 --
 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] disable seqscan

2011-05-23 Thread Andreas Kretschmer
Nick Raj nickrajj...@gmail.com wrote:

 
 On Mon, May 23, 2011 at 5:44 PM, Andreas Kretschmer 
 akretsch...@spamfence.net
 wrote:
 
 Andrew Sullivan a...@crankycanuck.ca wrote:
 
  On Mon, May 23, 2011 at 05:31:04PM +0530, Nick Raj wrote:
   Hi,
   I have build an index. When, i execute the query, it gives the result
 by
   sequential scan, not by using my index.
 
   For that, i have set enable_seqscan=off in postgresql.conf. But it
 still
   going through sequential scan.
 
  It sounds like your index can't actually be used to satisfy your
  query.  Without seeing the table definition, index definition, and
  query, however, it's pretty hard to give you a real answer.
 
 ... and the output produced by
 
 explain analyse insert your query
 
 Explain analyze of my query
 explain analyze select * from vehicle_stindex where ndpoint_overlap('
 (116.4,39.3,2008/02/11 11:11:11),(117.8,39.98,2008/02/13 11:11:11)
 ',stpoint);
 QUERY
 PLAN   
 
 --
  Seq Scan on vehicle_stindex  (cost=100.00..1050870.86 rows=
 698823 width=66) (actual time=3285.106..3285.106 rows=0 loops=1)
Filter: ndpoint_overlap('(116.40,39.30,2008-02-11
 11:11:11+05:30),(117.80,39.98,2008-02-13 
 11:11:11+05:30)'::ndpoint,
 stpoint)
  Total runtime: 3285.153 ms
 (3 rows)
 
 
 Table Defination
 
 Table public.vehicle_stindex
  Column  |  Type   | Modifiers
 -+-+---
  regno   | text|
  stpoint | ndpoint |
 Indexes:
 stindex gist (stpoint)
 
 It has 2099192 tuples.
 
 
 Index defination
 create index stindex on vehicle_stindex using gist(stpoint).
 
 
 I have defined a datatype called ndpoint. It works same as contrib/cube
 code (cube datatype).
 Query is working fine. I mean no error from query or my datatype. All are
 giving right result.
 
 If anything more to mention, then tell me

Okay. Sorry, i'm not familiar with gist and gist-functions and postgis
and so on, but i think, your index is unuseable in this case.

To use the index you have to build a functional index with this
function, for instance (i'm not sure if this is correct, as i said, i'm
not familiar with this):

create index stindex on vehicle_stindex (ndpoint_overlap(...))

Simple example for an functional index:

test=# create table foo (f text);
CREATE TABLE
Time: 5,555 ms
test=*# create index idx_foo on foo(md5(f));
CREATE INDEX


now you have an index on the md5-sum from foo.f, and you can say:

select * from foo where md5(f) = md5('test')

I think, that's the way you are looking for.


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.  (Linus Torvalds)
If I was god, I would recompile penguin with --enable-fly.   (unknown)
Kaufbach, Saxony, Germany, Europe.  N 51.05082°, E 13.56889°

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


[GENERAL] Postgres 8.3.5 - ECPG and the use of descriptors and cursors in multi-threaded programs

2011-05-23 Thread Leif Jensen
Hello Guys,

In a multi-threaded server program using Postgresql 8.3.5 with ECPG 
interface for C, we have problems using descriptors (and possibly cursors).

We have created a common database interface module with basically 1 
function: SQLExec(). In the 'select' part of this function we (statically) 
allocate a descriptor as shown below.

This seems to be working most of the time, but looking at the generated C 
code from the ecpg compiler and the associated library functions, we are not 
sure whether we should put mutex locks around the 'select' part to avoid 
several threads are using the same execdesc at the same time.

We have made sure that each thread uses their own and only their own 
database connection, but are unsure whether the ecpg library functions is able 
to handle multiple use of the statical name execdesc ?


static int SQLExec( const char *thisDbConn, char *paramStmt )
{
  EXEC SQL BEGIN DECLARE SECTION;
  const char *_thisDbConn = thisDbConn;
  char *stmt = paramStmt;
  EXEC SQL END DECLARE SECTION;

 .
 .
  if( select ) {
 .
 .
EXEC SQL AT :_thisDbConn ALLOCATE DESCRIPTOR execdesc; line = __LINE__;

  EXEC SQL AT :_thisDbConn PREPARE execquery FROM :stmt; line = __LINE__;

  EXEC SQL AT :_thisDbConn DECLARE execcurs CURSOR FOR execquery; line = 
__LINE__;

  EXEC SQL AT :_thisDbConn OPEN execcurs; line = __LINE__;

while( ok ) {

  EXEC SQL AT :_thisDbConn FETCH IN execcurs INTO SQL DESCRIPTOR execdesc;
   .
   (handle data per row, using execdesc)
   .
}
.
(deallocation of stuff)
.
  }
}

   We experience spurious crashes with SIGSEGV and tracebacks of the core dump 
usually ends within some ecpg library function, hence this question.

   Please help,

 Leif

-- 
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] Where are plpy.execute python commands issued?

2011-05-23 Thread Sim Zacks

On 05/23/2011 06:44 AM, Michael McInnis wrote:

I've seen numerous references to this syntax but haven't found where 
you issue the command.


Tried it in a testpython.py file, no luck.
Can't find a plpy file anywhere.

I know it's going to be simple but need help.
rv = plpy.execute(SELECT * FROM my_table, 5)
Thanks

Michael McInnis 6033 44th Ave. N.E. Seattle, WA 98115 206 517-4701


You have to run it as a plpythonu function as in:

create function test() returns int as
$$
rv=plpy.execute(SELECT * FROM my_table, 5)
for row in rv:
do something
return 1
$$ langauge 'plpythonu';




Re: [GENERAL] disable seqscan

2011-05-23 Thread Tom Lane
Nick Raj nickrajj...@gmail.com writes:
 Andrew Sullivan a...@crankycanuck.ca wrote:
 It sounds like your index can't actually be used to satisfy your
 query.  Without seeing the table definition, index definition, and
 query, however, it's pretty hard to give you a real answer.

 explain analyze select * from vehicle_stindex where
 ndpoint_overlap('(116.4,39.3,2008/02/11 11:11:11),(117.8,39.98,2008/02/13
 11:11:11)',stpoint);

 I have defined a datatype called ndpoint. It works same as contrib/cube
 code (cube datatype).

Indexes can only be used with WHERE conditions that are of the form
indexed_column  operator  some_expression
where the operator is one of those belonging to the index's operator
class.  You haven't told us what operators you put into the operator
class for this new data type, but in any case the function
ndpoint_overlap is not one of them.

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


[GENERAL] Using right() in a view

2011-05-23 Thread Chrishelring
Hi all,

please foregive me for this rather trivial question, but I´ve worked in it
for quite som time and could use som help now. :)

I have a table where it want to create a idkey using our municipality number
+ the road number + the housenumber.

The municipality and housenumber is in a fixed size, so they are okay. But
the road number differs from two digits up to four. I was then thinking
about doing something like this:

CREATE OR REPLACE VIEW test AS 
SELECT 
  right(cast('000' as text) || cast(road_number as text), 4) AS GEO_ADRESSE
  
FROM rk_ois.bbrbygning
WHERE ejerlav  0

to ensure that the road_number would be a fixed size (four digitis).
Unfortunately this doesn't work. 

Any idea on how to solve this?

Christian

--
View this message in context: 
http://postgresql.1045698.n5.nabble.com/Using-right-in-a-view-tp4419141p4419141.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

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


[GENERAL] Postgre Client only install on Linux- 8.4.7

2011-05-23 Thread Chitra Vasamsetty
Hi,

How can i install only the postgre client on an RHEL 5.5 machine??
I have installed the server running the ./postgresql-8.4.7-1-linux-x64.bin
command.

Any help appreciated...

Thanks
Chitra


[GENERAL] Postgre Client only Install on Linux- 8.4.7

2011-05-23 Thread Chitra
Hi,

How can i install only the postgre client on an RHEL 5.5 machine??
I have installed the server running the ./postgresql-8.4.7-1-linux-x64.bin
command.

Any help appreciated...
Thanks
Chitra


Re: [GENERAL] Using right() in a view

2011-05-23 Thread Bosco Rama
Chrishelring wrote:
 
 CREATE OR REPLACE VIEW test AS 
 SELECT 
   right(cast('000' as text) || cast(road_number as text), 4) AS GEO_ADRESSE
   
 FROM rk_ois.bbrbygning
 WHERE ejerlav  0
 
 to ensure that the road_number would be a fixed size (four digitis).
 Unfortunately this doesn't work. 

Try using:
   select to_char(road_number, 'FM') as GEO_ADRESSE

HTH

Bosco.

-- 
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] Postgres 8.3.5 - ECPG and the use of descriptors and cursors in multi-threaded programs

2011-05-23 Thread Bosco Rama
Leif Jensen wrote:
 
 This seems to be working most of the time, but looking at the generated C
 code from the ecpg compiler and the associated library functions, we are
 not sure whether we should put mutex locks around the 'select' part to
 avoid several threads are using the same execdesc at the same time.
 
 We have made sure that each thread uses their own and only their own
 database connection, but are unsure whether the ecpg library functions is
 able to handle multiple use of the statical name execdesc ?

You are most probably trashing memory by using the same descriptor name in
multiple threads.  However, given that you have already spent the effort to
have the connections 'thread-dedicated' I think that rather than creating a
critical path through an area that is intentionally supposed to be mutli-
hreaded, I'd be inclined to use the connection name (or some derivation of
it) as the name of the descriptor.  I haven't used descriptors in ecpg so I
don't know if the syntax works, but you could try:

exec sql char *dname = _thisDbConn;  // Or some derivation

EXEC SQL AT :_thisDbConn ALLOCATE DESCRIPTOR :dname;
...
EXEC SQL AT :_thisDbConn FETCH IN execcurs INTO SQL DESCRIPTOR :dname;
...
EXEC SQL DEALLOCATE DESCRIPTOR :dname;


Just a thought.

Bosco.

-- 
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] Postgre Client only Install on Linux- 8.4.7

2011-05-23 Thread John R Pierce

On 05/23/11 5:16 AM, Chitra wrote:

How can i install only the postgre client on an RHEL 5.5 machine??
I have installed the server running the 
./postgresql-8.4.7-1-linux-x64.bin command.


use the rpms from the yum repository, postgresql-libs is the runtime 
client software.


see http://yum.pgrpms.org/  and http://yum.pgrpms.org/howtoyum.php

frankly, I would use that version for the server too, rather than that 
.bin thing




--
john r pierceN 37, W 123
santa cruz ca mid-left coast


--
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] Trapping errors

2011-05-23 Thread David Johnston
UPDATE tbl SET score = divide_double_default(score, s, 1e-200) ...
UPDATE tbl SET score = multiply_double_default(score, s, 9) ...

Code the divide_double_default/multiply_double_default functions with error 
handling that will return the desired value (either zero or the supplied 
parameter) if an exception is thrown; probably with a WARNING/NOTICE raised as 
well.

David J.


 -Original Message-
 From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-
 ow...@postgresql.org] On Behalf Of Shane W
 Sent: Monday, May 23, 2011 4:08 PM
 To: pgsql-general@postgresql.org
 Subject: [GENERAL] Trapping errors
 
 Hello list,
 
 I have a table with double precision columns and update queries which
 multiply and divide these values. I am wondering if it's possible to catch
 overflow and underflow errors to set the column to 0 in the case of an
 underflow and a large value in the case of an overflow.
 
 Currently, I have an exception handler in a PLPGSQL ufunction that sort of
 does this.
 
 begin
 update tbl set score = score/s
 exception when numeric_value_out_of range then update tbl set score=0
 where cast(score/s as numeric)  1e-200 end;
 
 But this is messy since the exception needs to rescan the entire table if even
 one row fails the update. Is there a better way to do this?
 
 Best,
 Shane
 
 
 --
 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: [GENERAL] strange behaviour in 9.0.2 / ERROR: 22003: value out of range: overflow

2011-05-23 Thread rudi
On 20 Mai, 22:55, rudi rudi.stras...@gmail.com wrote:
 Hi all,

 I feel like I hit a bug in postgres 9.0.2 with a query like this
 (there's actually a quite complicated view hidden behind), however
 note
 the  'IN' selection contains two identical keys. When I execute a
 similar query without the duplicate, the query returns, so I would
 conclude it shoud be a bug.

 This query fails as you can tell from the output:

 mydb=# select * from cpcpk_by_lot where foundry='x' and lot='valerie'
 and epclass='wac' and area='device' and parameter in
 ('RVT_2P_NOM_1UX5_N_VTSAT','RVT_2P_NOM_1UX5_N_VTSAT');
 ERROR:  22003: value out of range: overflow
 LOCATION:  float4mul, float.c:750

 while the a practically identical query returns with the expected
 result?

 mydb=# select * from cpcpk_by_lot where foundry='x' and lot='valerie'
 and epclass='wac' and area='device' and parameter in
 ('RVT_2P_NOM_1UX5_N_VTSAT');

 I hope anyone can give me a hint how to proceed

 Best regards,
 Rudi

I found out that the issues is caused by overflows in floating point
(REAL) operation. After some additional debug info using VERBOSITY
that became more or less evident. I wonder whether the behaviour can
be optimized, such that the individual value can be set to 'nan'
instead of causing a fail for the entire query. In a productive
environment this would scare the hell out of me.

In case someone has ideas how such conditions can be avoided, please
forward me some hints. I tend to believe that there must be a better
soluation than the one which is currently in place.

Best regards,
Rudi

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


[GENERAL] Postgres questions

2011-05-23 Thread Trenta sis
Hi,


I have Debian Lenny server with Postgres 8.3 that is workin correctly, but I
have some questions about this installation.

This server is working whitout any problem but it is a little critical and I
need to know how can I do...

- I need to connect from postgres to other database (linked server) no
postgres (for example with jdbc or odbc). I have tried to work with dbi-link
with sql, it seems to work but with poor performance and whit other database
different mssql is not working. What possible options exsits with 8.3? and
with other versions?

- This server has some critical applications and I need high availability,
but I'm not sure about possible options for this versions or similar. I have
thought about active/active, active/passive or active/read-only but I'm not
sure what are real options, and what could be a possible environment for
this situation

Thanks


Re: [GENERAL] Postgres questions

2011-05-23 Thread Craig Ringer

On 24/05/2011 6:10 AM, Trenta sis wrote:


- I need to connect from postgres to other database (linked server) no
postgres (for example with jdbc or odbc). I have tried to work with
dbi-link with sql, it seems to work but with poor performance and whit
other database different mssql is not working. What possible options
exsits with 8.3? and with other versions?


DBI-link is probably your best bet. Another possibility is to use an 
in-database procedural language to talk to the other database - for 
example, PL/perl via DBI::DBD or PL/Python via a PEP-249 
(http://www.python.org/dev/peps/pep-0249/) database driver like pymssql.


Otherwise you can do the data sharing/sync/whatever via a client 
application that has connections to PostgreSQL and to the other database 
of interest. That's often a better choice for more complex jobs.


Perhaps it'd help if you explained why you need this and what you want 
to accomplish with it?



- This server has some critical applications and I need high
availability, but I'm not sure about possible options for this versions
or similar. I have thought about active/active, active/passive or
active/read-only but I'm not sure what are real options, and what could
be a possible environment for this situation


It depends a LOT on what your needs are, and what your budget is. You 
have some basic questions to ask yourself, like:


- Do I need true HA with failover, or just to protect against data loss?

- Can I modify my apps to be aware of failover, or does failover have to
  be transparent?

- Do I need multi-site failover or is all access of interest within
  one site?

- What kind of guarantees do I need about data loss windows at failover
  time? Can I afford to lose the last x transactions / seconds worth
  of transactions? Or must absolutely every transaction be retained
  at all costs?

Once you've worked out the answers to those kinds of questions, THEN you 
can look at bucardo, slony-I, PostgreSQL 9.0 native replication, etc etc 
as well as failover-control options like heartbeat and decide what might 
be suitable for you.


--
Craig Ringer

Tech-related writing at http://soapyfrogs.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


[GENERAL] PostgreSQL and SSIS

2011-05-23 Thread Bailey, Rick
I have an Microsoft SQL Server IS job that has been running in production for 
several years.  It pulls data from a PostgreSQL 8.4.2 database on Linux into an 
SQL Server 2005 installation on Windows  Server 2003 (all 32-bit).  I am 
re-writing this in a test environment that consists of the same PostgreSQL 
database and an SQL Server 2008R2 installation on Windows Server 2008R2 (all 
64-bit).
On the Windows Server 2008R2 machine, I installed 64 bit Postgres ODBC drivers 
and found that I could not see them when creating an ADO.net connection manager 
in BIDS.  A bit of googling later, I removed the 64 bit drivers and installed 
32-bit Postgres ODBC drivers and set up DSNs usning 
windows\SysWOW64\odbcad32.exe.  When setting up the DSNs, clicking the test 
button returned 'Connection successful'.
Back to BIDS, create a new ADO.net connection manager, ODBC Data Provider, 
select the DSN name in 'Use user or system data source name', hit the test 
connection button.  It returns 'Test connection succeeded'.  Create  a data 
flow task, edit, add an ADO.NET source, edit, select the new connection 
manager, Data access mode is set to 'Table or view', click the drop down for 
'Name of the table or view:', it says loading and will sit there like that 
forever.  If I click it again, it returns the following error message:
'Could not retrieve the table information for the connection manager 
'PostgreSQL30'.  Object reference not set to an instance of an object. 
(Microsoft.DataWarehouse)'
If I select 'SQL Command' as the Data Access mode, and enter any SQL Command 
(eg select * from PostgresTable) and hit the Preview button, the expected data 
is returned.
My question is why can it not return the list of tables, but it can return data.
Any help would be appreciated.


Rick Bailey
Database Specialist
Materials Research Institute
123 Land  Water Building
University Park, PA 16802
814-863-1294



Re: [GENERAL] how to start a procedure after postgresql started.

2011-05-23 Thread jun yang
2011/5/23 Craig Ringer cr...@postnewspapers.com.au:
 On 23/05/2011 10:13 AM, jun yang wrote:

 actually, we will write the procedure in pl/python,then fork a new
 thread or a new process which is easy.

 Yikes. Be careful there - it's not as easy as you think it is.

 Spawning a new thread within a PostgreSQL backend is a very, very, very bad
 idea unless you know EXACTLY what you are doing. Do not do it if there is
 any alternative.

 As for spawning a new process: a PostgreSQL backend's environment isn't
 guaranteed to be what you expect. I don't just mean environment variables.
 The most likely surprise will be finding yourself running in quite a
 limiting SELinux context if SELinux is present, but I'm sure there are more
 possible quirks. Also, on unix/linux, if the backend process that invoked
 your helper dies, your helper will be re-parented to init not to the
 postmaster, which won't be what you expected.

thanks for the info,i am just not have such deep learn of pg internal,
i am on user level,not hacker,so the mail is in pgsql-general,not
hacker list.

 There's been discussion of adding the ability for the postmaster to start
 helper daemons, and if that were merged you could use a helper started
 alongside the postmaster to do the work. Right now, though, you're better
 off doing things how PgAgent etc do it, that is out-of-process via a
 regular
 Pg connection.

 then the one sitting between pg and borker is a helper daemon,it is
 great,more info about that?
 PgAgent is nice,i am just wondering why it can't be integrated in
 standard pg install,cause security? functionality?

 Doing just that is sometimes discussed, and I think it'll happen eventually.
 First, though, PostgreSQL's postmaster needs to be altered so that it can
 start and manage helper programs and daemons. As of now, that hasn't
 happened yet, or at least nobody has written a good enough patch that the
 core team have been willing to accept it.

 if helper daemon integrated in pg,the PgAgent can be a helper daemon too.
 i'd like helper daemon can operate like windows service,you can
 disable it,make it mannual start, or auto start with pg.

 Your best bet at the moment is to integrate with operating system service
 mechanisms. On Windows, use services. On UNIX/Linux, use the init system. On
 Mac OS X, use launchd.

 Part of the reason the postmaster hasn't been altered to support managing
 daemons is because some people (understandably) think that that's the OS's
 job, and not something PostgreSQL should duplicate.

well,from user viewpoint,i prefer that pg bundle with such
function,like extension in pg,the function default is disable.make it
easier for those who need it will be a promotion for pg.
many commercial db production include such a schedule function, not
only for making money,there is user need in practice.

 In an ideal world I'd agree with them, but the current computing world is
 far from ideal.  Every OS is annoyingly different in how it manages daemons,
 and many init systems are painfully limited in terms of the kind of events
 they can handle. Most can't even handle If service x exits, do y.
 Monitoring capabilities and the like must be individually provided by each
 service if they want to be even a little bit portable.

 Nonetheless, I think that's your best bet right now.

yes,it is so complicated for a common user to do such things.
 --
 Craig Ringer

 Tech-related writing at http://soapyfrogs.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] how to start a procedure after postgresql started.

2011-05-23 Thread Rick Genter

On May 23, 2011, at 9:46 PM, jun yang wrote:

 thanks for the info,i am just not have such deep learn of pg internal,
 i am on user level,not hacker,so the mail is in pgsql-general,not
 hacker list.

What you are asking to do is not a typical user function. It would be more 
appropriate for a hacker list.
--
Rick Genter
rick.gen...@gmail.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] how to start a procedure after postgresql started.

2011-05-23 Thread Craig Ringer
On 24/05/11 12:46, jun yang wrote:

 thanks for the info,i am just not have such deep learn of pg internal,
 i am on user level,not hacker,so the mail is in pgsql-general,not
 hacker list.

Then you really, really, REALLY don't want to start a thread within the
backend, and should avoid spawning processes from backends too. To get
either approach right will require a much deeper understanding of how Pg
works.

 Part of the reason the postmaster hasn't been altered to support managing
 daemons is because some people (understandably) think that that's the OS's
 job, and not something PostgreSQL should duplicate.

 well,from user viewpoint,i prefer that pg bundle with such
 function,like extension in pg,the function default is disable.make it
 easier for those who need it will be a promotion for pg.
 many commercial db production include such a schedule function, not
 only for making money,there is user need in practice.

Yep, I think it'd be nice. Nobody has volunteered to write such a
feature yet, though, and nobody is stepping up to pay someone else to
write it. Or at least any efforts so far haven't reached
production-quality committable code.

The downside of working with an open source database is that there's no
incentive to write marketing-checkbox features. Someone has to actually
want to put in the time and effort to implement it, usually because they
want to use it.

 yes,it is so complicated for a common user to do such things.

... which is why the VAST majority of people achieve what they need
using a separate daemon or just integrate this sort of functionality
into their middleware. Neither option is difficult to do.

What you want to do - integrate your app directly and completely into
the database - is not something that a common user typically wants to do
in the first place.

It's more common for people who want to hide the database behind a
messaging system to instead write a program that accepts messages and
embed a database like Berkeley DB, SQLite or Firebird directly into
their program, rather than the other way around. PostgreSQL cannot be
embedded that way, it's not designed for that kind of use.

--
Craig Ringer

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