[GENERAL] Misunderstanding deadlocks

2014-10-16 Thread snacktime
I'm confused about how deadlock detection and breaking deadlocks works.
Googling around it seems that the server should be detecting deadlocks and
aborting one of the queries.

But I'm getting occasional deadlocks that literally hang forever.  I'm
assuming they are deadlocks because they show up when running the queries I
got from this url:

https://wiki.postgresql.org/wiki/Lock_Monitoring


I'm running postgres 9.3 on ubuntu, configuration is the default.

Chris


[GENERAL] Postgres as key/value store

2014-09-27 Thread snacktime
I'm looking for some feedback on the design I'm using for a basic key/value
storage using postgres.

Just some quick background.  This design is for large scale games that can
get up to 10K writes per second or more.  The storage will be behind a
distributed memory cache that is built on top of Akka, and has a write
behind caching mechanism to cut down on the number of writes when you have
many updates in a short time period of the same key, which is common for a
lot of multiplayer type games.

I have been using Couchbase, but this is an open source project, and
Couchbase is basically a commercial product for all intents and purposes,
which is problematic.  I will still support Couchbase, but I don't want it
have to tell people if you really want to scale, couchbase is the only
option.

The schema is that a key is a string, and the value is a string or binary.
I am actually storing protocol buffer messages, but the library gives me
the ability to serialize to native protobuf or to json.  Json is useful at
times especially for debugging.

This is my current schema:

CREATE TABLE entities
(
  id character varying(128) NOT NULL,
  value bytea,
  datatype smallint,
  CONSTRAINT entities_pkey PRIMARY KEY (id)
);

CREATE OR REPLACE RULE entities_merge AS
ON INSERT TO entities
   WHERE (EXISTS ( SELECT 1
   FROM entities entities_1
  WHERE entities_1.id::text = new.id::text)) DO INSTEAD  UPDATE
entities SET value = new.value, datatype = new.datatype
  WHERE entities.id::text = new.id::text;

Additional functionality I want is to do basic fuzzy searches by key.
Currently I'm using a left anchored LIKE query.  This works well because
keys are left prefixed with a scope, a delimiter, and then the actual key
for the data.  These fuzzxy searches would never be used in game logic,
they would be admin only queries for doing things like  obtaining a list of
players.  So they should be infrequent.

The scope of the query ability will not expand in the future.  I support
multiple backends for the key/value storage so I'm working with the lowest
common denominator.  Plus I have a different approach for data that you
need to do complex queries on (regular tables and an ORM).

 Chris


[GENERAL] Mirroring existing mysql setup

2008-12-18 Thread snacktime
Where I work we use mysql for a fairly busy website, and I'd like to
eventually start transitioning to postgres if possible.   The largest
obstacle is the lack of replication as a core feature.  I'm well aware
of the history behind why it's not in core, and I saw a post a while
back saying it would be in 8.4.  I'd like to say I think this is a
very good idea, and I know a number of shops personally that did not
go with postgres just for this reason.

So anyways our general setup is that we have one master replicating to
one slave.  We use the slave for generating various leaderboard stats
for our games.  Most of these get generated every 4 hours.   If we
wanted to duplicate this on postgres I'm not sure which replication
option would work best.  Last time I looked at slony you had to edit
configs for each table  you wanted to replicate, and the whole setup
was more complex then it needed to be.  If it's still like that, I
think we would lose more then we gain by moving to postgres.  Once
setup, the replication needs to be free of daily administration other
then routine automated tasks.  We add new tables/remove old ones
almost on a daily basis.

Now for one of the main things we don't like about mysql.  You can't
add indexes without locking the whole table, which means you can't go
back and add indexes later on a production app without shutting down
the whole system.   The effect his has had is that when we add new
features to our games that would normally require an additional
column, we have to add a new table since we can't add an index to the
old table.   When you add indexes in postgres, how much of a
performance hit will the database be taking while adding the index?
I haven't worked on a postgres installation that's as busy as our
mysql installation is.  We get roughly 3-4 million page views per day,
with each page view probably averaging 4-6 db queries.  Probably 20%
of these are cached.  In addition we have our slave which does far
fewer, but more complicated queries.  Quite a few of our tables will
gain thousands of rows per day, some tens of thousands.  Some of our
busiest tables have tens of millions of rows.  We could start to
archive some of these.

Chris

-- 
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] Reversing transactions on a large scale

2008-11-21 Thread snacktime
On Thu, Nov 20, 2008 at 4:06 PM, Scott Marlowe [EMAIL PROTECTED] wrote:
 On Thu, Nov 20, 2008 at 4:36 PM, snacktime [EMAIL PROTECTED] wrote:
 Right now we are running mysql as that is what was there when I
 entered the scene.  We might switch to postgres, but I'm not sure if
 postgres makes this any easier.

 We run a couple of popular games on social networking sites.  These
 games have a simple economy,and we need to be able to time warp the
 economy back in time, which means reverting a whole lot of
 transactions and inventories.  Our games generate around 1 million
 user transactions per hour, which results in inserts/updates on 4
 times that many rows.   Using PIT recovery would be a very reliable
 way to accomplish this, but I'm wondering how long it would take.  If
 it takes a full day to roll back an hour of game time, then I need to
 find another solution.

 PITR is pretty fast, since it sequentially applies changes to the
 database as fast as it can.  Your hardware has a lot to do with this
 though.  Applying changes to a machine with plenty of memory, fast
 CPUs, and a big rockin RAID-10 array will of course be much faster
 than doing the same thing on a laptop.

 If you make base sets every night at midnight with snapshots, then
 it shouldn't take too long.  Is this gonna be a regular thing, or is
 this more of an occasional occurance when things in the game go
 horribly wrong?


It's primarily for when a bug screws up the economy, or if someone
finds a way to hack the economy.   Unfortunately these things happen
now and then.  Plus, these games are relatively short lived.  We might
get a million users the first month, but a year later the game is
dead.   So a generic solution using something like PITR would be good.
 It's not worth it to do it in code with the game having such a short
lifespan.

Chris

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


[GENERAL] Reversing transactions on a large scale

2008-11-20 Thread snacktime
Right now we are running mysql as that is what was there when I
entered the scene.  We might switch to postgres, but I'm not sure if
postgres makes this any easier.

We run a couple of popular games on social networking sites.  These
games have a simple economy,and we need to be able to time warp the
economy back in time, which means reverting a whole lot of
transactions and inventories.  Our games generate around 1 million
user transactions per hour, which results in inserts/updates on 4
times that many rows.   Using PIT recovery would be a very reliable
way to accomplish this, but I'm wondering how long it would take.  If
it takes a full day to roll back an hour of game time, then I need to
find another solution.

Chris

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


[GENERAL] Conditional updateable view

2007-12-15 Thread snacktime
I can't seem to find an example of how to add restrictions to the
where clause of an updateable view created via the rule system.  For
example I don't want the update to complete if a where clause is
missing entirely, and in some cases I want to only allow the update if
the where clause specifies a particular column.

Is there a way to do this?

Chris

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


[GENERAL] looking for some real world performance numbers

2007-10-21 Thread snacktime
I'm working through the architecture design for a new product.  We
have a small group working on this.  It's a web app that will be using
ruby on rails.  The challenge I'm running into is that the latest
conventional wisdom seems to be that since obviously databases don't
scale on the web, you should just not use them at all.  I have a group
of otherwise very bright people trying to convince me that a rdbms is
not a good place to store relational data because eventually it won't
scale.  And of course we don't even have version 1 of our product out
of the door.  I'll admit we do have a very good chance of actually
getting tons of traffic, but my position is to use a rdbms for
relational data, and then if and when it won't scale any more, deal
with it then.

So what would really help me is some real world numbers on how
postgresql is doing in the wild under pressure.  If anyone cares to
throw some out I would really appreciate it.

Chris

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


[GENERAL] Modeling bill/ship addresses

2007-08-05 Thread snacktime
I've been going back and forth on the best way to model this.

A user can have one to many bill and ship addresses.
An order can have one bill address and one to many ship addresses

Let's assume I have a single address table, with an address_type
column that is a foreign key to the address_types table.

Now to create the relationships between addresses and users/orders.  I
 could create a join table for holding the addresses that belong to
orders.  For example table order_addresses that has order_id and
address_id columns that are foreign keys on addresses and orders.

But what about just having two foreign keys in addresses?  order_id
and user_id?  Or is there a rule against having a null foreign key?

Also, is there a good database independent way to make the address
immutable once it's created?  I don't mind doing it at the application
level actually, as I'm using a MVC framework that makes it easy to
define that logic once in the model instead of spread out all over the
codebase.

Chris

---(end of broadcast)---
TIP 6: explain analyze is your friend


[GENERAL] server vendor recommendation

2007-03-07 Thread snacktime

Any recommendations for vendors that can build custom servers?
Specifically opteron based with scsi raid.

Chris

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


[GENERAL] schema design question

2007-02-24 Thread snacktime

Say you have 8 different data models that are related enough to share
roughly 70% of the same fields, but the shared fields are not always
the same.  And also within any given model, some fields can be empty.
The business logic is that data is pulled from all the data models and
put into a common format that has all the combined fields, and sent
over the wire as a transaction.

The models are different credit card transaction types.  Most of them
share a lot of common fields, but each one is different by about 3-6
fields, and each one has different requirements on which fields can be
empty and what their default values are.  In the past I've basically
used one table and modeled it after the message format that is sent to
the processor.  I'm thinking about creating a table for each
transaction type though to cut down on the number of empty fields for
each transaction type, and also to limit the number of options that is
allowed in each field.  For example across the transaction types
credit, capture, authorize, force, charge, and voice authorize the
authorization_source_code field might have 8 possible values, but in
any one transaction type it probably only has 3 at the very most.

Would most of you create a separate tabel for each transaction type?

I'm also curious how others would handle the batch closings.  In the
past I have created separate tables for open transactions and
transactions that have been captured/settled.  When a transaction is
captured it's moved to a different table instead of just having a
column to mark it as captured.  Normally I would select all the
transactions to capture, insert them into the captured table, delete
them from the open transactions table, process the batch, and if the
batch goes through commit everything.  That narrows down the number of
things that can go wrong after you have submitted the batch.  The
alternative would be to just have a column to mark transactions as
capture and leave them all in one table.  I've always been paranoid
about doing that because it leaves open the possibility of capturing
thousands of transactions twice if you have a bug, as opposed to a few
hundred at most.

I spent quite a few years working at payment gateways and am now
creating an open source platform that does the same thing that your
normal payment gateway does.  It's been a while since I've had the
chance to look at this problem in a fresh light.  Most of the
processing code at payment gateways is left pretty much untouched once
it's working, it's not something you go in and refactor every few
months even if it's not perfect.

Would appreciate any feedback.

Chris

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [GENERAL] [Slony1-general] Using slony with many schema's

2006-10-11 Thread snacktime

First, thanks for all the feedback.   After spending some more time
evaluating what we would gain by using slony I'm not sure it's worth
it.  However I thought I would get some more feedback before
finalizing that decision.

The primary reason for looking at replication was to move cpu
intensive SELECT queries to a slave.  However, by moving away from
schema's the report queries for all clients on the server become more
cpu intensive instead of just the clients with large data sets.  The
average distribution is that 95% of our clients have less then 5000
rows in any table, and the other 5% can have hundreds of thousands.
So by putting all the data into one schema, every report query now
gets run against a million or more rows instead of just a few  hundred
or thousand.  So all clients will see a drop in query performance
instead of just the clients with large amounts of data.

Chris

---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org/


Re: [GENERAL] [Slony1-general] Using slony with many schema's

2006-10-11 Thread snacktime

Sorry wrong list, this was meant for the slony list...

Chris

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [GENERAL] more anti-postgresql FUD

2006-10-11 Thread snacktime

1. create table test (id int4, aaa int4, primary key (id));
2. insert into test values (0,1);
3. Execute update test set aaa=1 where id=0; in an endless loop

I just did the test on PostgreSQL 7.4.12 and MySQL 5.0.22 (MyISAM,
sorry had no configured InnoDB). Ubuntu 6.0.6, AMD64, 2GB, default
database settings.

MySQL performs very well, approximately 15000-2 updates per second
with no degradation of performance.

PostgreSQL does approximately 1600 records per second for the first
1, then 200rps for the first 100k records, and then slower and
slower downgrading to 10-20 rps(!!!) when reaching 300k.


Something is wrong with your test code.  If I had to guess I would say
you did all the updates in a single transaction without committing
them, in which case yes it will slow down until you commit.

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match


Re: [GENERAL] using schema's for data separation

2006-09-29 Thread snacktime

On 9/29/06, Just Someone [EMAIL PROTECTED] wrote:

I am using a similar solution, and I tested it with a test containing
20K+ different schemas. Postgres didn't show slowness at all even
after the 20K (over 2 million total tables) were created. So I have
feeling it can grow even more.


That's good to know we haven't really tested it against that many
schema's, other then actually creating them to make sure there wasn't
some sort of hard limit or bug no one had run into before.
Performance with schema's is actually one thing I do like.  A query
for any one user is only hitting the data in the one schema, so users
with large data sets don't impact the query performance of users with
smaller data sets.

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[GENERAL] using schema's for data separation

2006-09-28 Thread snacktime

I'm re evaluating a few design choices I made a while back, and one
that keeps coming to the forefront is data separation.  We store
sensitive information for clients.  A database for each client isn't
really workable, or at least I've never though of a way to make it
workable, as we have several thousand clients and the databases all
have to be accessed through a limited number of web applications where
performance is important and things like persistant connections are a
must.  I've always been paranoid about a programmer error in an
application resulting in data from multiple clients getting mixed
together.  Right now we create a schema for each client, with each
schema having the same tables.  The connections to the database are
from an unprivileged user, and everything goes through functions that
run at the necessary privileges.  We us set_search_path to
public,user.  User data is in schema user and the functions are in the
public schema.  Every table has a client_id column.

This has worked well so far but it's a real pain to manage and as we
ramp up I'm not sure it's going to scale that well.  So anyways my
questions is this.  Am I being too paranoid about putting all the data
into one set of tables in a common schema?  For thousands of clients
what would you do?

Chris

---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


[GENERAL] Kill specific connection

2006-09-13 Thread snacktime

What's a safe way to kill a specific connection to the database?  I'm
testing some code that reconnects if a connection has timed out or
gone bad and I need to simulate a connection that has gone away.

Chris

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match


[GENERAL] implementing a read lock

2006-08-26 Thread snacktime

I have an application that processes credit card transactions,and
contains a table called authorizations.  The authorizations table
contains information returned by the bank necessary to capture the
transaction.   Nothing should block the application from inserting new
rows into the authorizations table.  When the authorizations are
captured, one or more rows will be fetched, captured, and if
successful the rows will be deleted.  No updates are done on the
table, only inserts or deletes.   Naturally I want to prevent
different instances of the same application  from trying to select the
same rows to capture, resulting in duplicate charges.  I can't lock
the whole table because new authorizations are constantly coming in.
Is creating a separate table that I use just as a lock table the best
approach?

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


[GENERAL] alternative to using a sequence

2006-08-25 Thread snacktime

I have an application that processes financial transactions.  Each of
these transactions needs to be sent with a sequence number.  It starts
at 1 and resets to 1 once it hits 8000.   I'm trying to think of the
most elegant solution without having to create a sequence for each
user (there are hundreds).  There is a table that holds the
configuration parameters for each merchant, so a field in that table
to hold the sequence number would be ideal.  In the past I've used
sequences as well as just a field which I query then update.  Any
other ideas?

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [GENERAL] User privileges in web database applications

2006-06-30 Thread snacktime

Both connection pooling and using the superuser with SET SESSION
AUTHORIZATION both have their uses.   You might have an application
that processes some type of transaction and inserts data into a users
schema or table, but where there are no user credentials available.
Then you might have a web interface for users to access that data
where user credentials are available.   We have this type of setup and
we use a superuser with SET SESSION AUTHORIZATION for the incoming
transactions.But we also have extensive security requirements that
demand we do things most people don't do.  Full security/code audits
every quarter, peer review and full testing for any new code,
hardware encryption for sensitive data and keys stored on tokens,
client certificate authentication for all web access, restrictive
firewall, etc..

Bottom line is that I'm paranoid about using SET SESSION
AUTHORIZATION, but it does have it's uses and can be used safely.

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [GENERAL] minimizing downtime when upgrading

2006-06-16 Thread snacktime

On 6/16/06, Richard Huxton dev@archonet.com wrote:


The other option would be to run replication, e.g. slony to migrate from
one version to another. I've done it and it works fine, but it will mean
slony adding its own tables to each database. I'd still do it one
merchant at a time, but that should reduce your downtime to seconds.



I'll have to take another look at slony, it's been a while.  Our
database structure is a bit non standard.  Being a payment gateway, we
are required to have a separation of data between merchants, which
means not mixing data from different merchants in the same table.
So what we do is every user has their own schema, with their own set
of tables.  Yes I know that's not considered the best practice design
wise, but separate databases would have caused even more issues, and
as it turns out there are some advantages to the separate schema
approach that we never thought of.  Last time I looked at slony you
have to configure it for each individual table you want replicated.
We have around 50,000 tables, and more are added on a daily basis.

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match


[GENERAL] minimizing downtime when upgrading

2006-06-15 Thread snacktime

Anyone have any tips for minimizing downtime when upgrading?  So far
we have done upgrades during scheduled downtimes.  Now we are getting
to the point where the time required for a standard dump/restore is
just too long.  What have others done when downtime is critical?  The
only solution we have been able to come up with is to migrate the data
on a per user basis to a new database server.  Each user is a
merchant, and the data in the database is order data.  Migrating one
merchant at a time will keep the downtime per merchant limited to just
the time it takes to migrate the data for that merchant, which is
acceptable.

Any other ideas?

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [GENERAL] Dynamic web sites with PostgreSQL

2005-11-10 Thread snacktime
On 11/9/05, Nicolay A Vasiliev [EMAIL PROTECTED] wrote:
Hello there!I'd like to ask the PostgreSQL community for the conseptual thing. Wedevelop our web sites using MySQL. We like this for its high speed andfulltext search feature. But nowadays our projects are growing fast and
we afraid our MySQL won't be able to perform large amount of complexcomplicated queries. So we get a question about altenative SQL server.In fact there are not too much from open source SQL servers, I think
only 2 serious: PostgreSQL and MaxDB. May I sak you about words foradvocacy or accusation for each of these database servers?
Run as fast as you can away from MaxDB. I've looked at the source
in detail, and my money is that mysql ab will never really do anything
with it. It's just a huge mess. The documentation is
probably the worst I have ever seen, the command line utilities have so
many options and are so poorly documented that it takes forever to
figure out how to do the most basic stuff. Exporting and
importing data is also a pain. I really can't say enough bad
things about MaxDB. Maybe it was good a few years ago, but right
now it's a huge step backwards from most anything else you could use,
including mysql. 

Chris


Re: [GENERAL] Oracle buys Innobase

2005-10-10 Thread snacktime
On 10/7/05, Jim C. Nasby [EMAIL PROTECTED] wrote:
http://lnk.nu/prnewswire.com/4dv.pl--Jim C. Nasby, Sr. Engineering Consultant[EMAIL PROTECTED]Pervasive Software
http://pervasive.comwork: 512-231-6117vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster
First thing that comes to my mind is that Oracle is setting the stage to buy them out. 


Re: [GENERAL] per user logging

2005-09-09 Thread snacktime
I believe it is possible for a superuser to do something likeALTER USER victim SET log_min_messages = whatever, so that the
log verbosity is different for different users.regards,
tom lane
I'll try that and see how it works.



[GENERAL] per user logging

2005-09-08 Thread snacktime
I'm pretty sure the answer to this is no, but just in case I've missed
something. Is there a way to configure the server so it only logs
for specific users? 

Chris


[GENERAL] changing default lockfile location

2005-08-05 Thread snacktime
I'm trying to run two database clusters on the same box.  Both are
bound to their own ip but use the same port.  I can't see a way to
change the location of the lockfile on a per cluster basis though.  Is
there one?

Chris

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [GENERAL] changing default lockfile location

2005-08-05 Thread snacktime
On 8/5/05, snacktime [EMAIL PROTECTED] wrote:
 I'm trying to run two database clusters on the same box.  Both are
 bound to their own ip but use the same port.  I can't see a way to
 change the location of the lockfile on a per cluster basis though.  Is
 there one?
 
 Chris
 
Never mind, I figured out the socket file is also the lockfile.

Chris

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [GENERAL] Transparent encryption in PostgreSQL?

2005-07-13 Thread snacktime
On 7/13/05, Matt McNeil [EMAIL PROTECTED] wrote:
 Greetings,
 I need to securely store lots of sensitive contact information and
 notes in a freely available database (eg PostgreSQL or MySQL) that will be
 stored on a database server which I do not have direct access to. 
 This database will be accessed by a PHP application that I am
 developing.  However, I also need to be able to search/sort these data
 with the database functions (SELECT, ORDER BY, etc) so encrypting on
 the client side (web application) or using encryption of specific fields 
 would not work.  (For example, I need to encrypt
 contacts' names, but need to be able to search for results by name). (I
 realize I could load the entire table into memory with PHP and
 process/search/sort it there, but
 that's obviously not a very good solution).  Ideally I would like to
 encrypt entire tables.  I read something about the pgcrypto contrib
 module, but have't been able to discern if it can do ecryption in a
 transparent way (e.g. so that I can do regex searches on the data).
  
 My sense is that this is a difficult problem.  However, I made the
 mistake of promising this functionality, 
 so I'm scrambling to figure out some kind of solution.  Any
 suggestions?

Go back to your client and renegotiate?  That would be my first
option.   Encryption isn't all it's cracked up to be, especially when
most people think they can ignore application level security just by
encrypting their data.

One possible compromise might be to lower case the name, strip out any
spaces or punctuation, split it into first and last name (if it's web
based use separate input fields), and then hash those values and stick
them in their own rows.  You would also have the full name encrypted
in it's own row.  To search you lower case the search string, strip
spaces, hash the value, and perform the query.  Kind of a hack but it
works.

Chris

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


[GENERAL] strange problem with pl/pgsql function caching of bad values

2005-07-11 Thread snacktime
I have a very strange issue that I'm not sure how to debug.  This is
on postgresql 8.0.0rc5, Freebsd 5.4.  Yes I know I should be upgrading
this version and it's scheduled, but it can't happen for another week
and for all I know this might still be an issue in current versions of
postgresql.

First the function in question:

CREATE OR REPLACE FUNCTION cancel_subscription_bysubid(varchar)
returns integer AS '
DECLARE

in_s_oid varchar;
in_active varchar;
status integer;

BEGIN
   in_s_oid := $1;
   in_active := 0;

status := active from recurbilling_transactions where s_oid = in_s_oid;

IF status = 0  THEN
  RETURN 0;
ELSIF status = 1 THEN
  EXECUTE ''update recurbilling_transactions set active= ''
||in_active|| '' WHERE s_oid ='' || quote_literal(in_s_oid);
  RETURN 1;
ELSE
  RETURN 2;
END IF;

END
' LANGUAGE 'plpgsql' SECURITY DEFINER;

The 'active' column is an integer NOT NULL.  s_oid is a varchar.  

Every few days the database gets into a state where this function
starts returning a value of 2 even though the value of 'active' is 1
or 0.  Even stranger is that not all sessions will do this.  We used
cached connections via the perl DBI, and once this starts happening
some sessions return the bad value while others work correctly.  Once
the database is in this state testing the function via psql at the
command line will always result in the function returning a value of
2, while some of the perl DBI connections will still be returning 0 or
1.  I'm assuming that at some point all new sessions get hosed and
it's the older sessions which still work.

Restarting the database puts things back to normal and the function
then works correctly again for a while.

One other thing about our particular setup is that we use separate
schema's for all user data and the functions go in the public schema. 
So before executing this function we issue something like 'set_path to
username,public'.

Chris

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


[GENERAL] upgrading from 8.0 rc5

2005-07-11 Thread snacktime
Do I need to do a full dump/restore when migrating from 8.0 rc5 to the
latest 8.0.3?

Chris

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [GENERAL] strange problem with pl/pgsql function caching of bad values

2005-07-11 Thread snacktime
  One other thing about our particular setup is that we use separate
  schema's for all user data and the functions go in the public schema.
  So before executing this function we issue something like 'set_path to
  username,public'.
 
 Mph.  Are you expecting the function to work for more than one such path
 value over the life of a connection?  Maybe you need to do the selection
 part with an EXECUTE not only the update.  As-is, the first execution
 will latch down which copy of recurbilling_transactions will be used
 for the selection, regardless of later changes in search_path.
 

Argh...  I knew better.  Yes i need to use EXECUTE because it is used
across multiple paths.

Chris

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq