I have an application where each user session opens and maintains a
long-lived connection to the postgresql backend database.
I need to keep a small amount of information (things like a unique
session identifier, the application - as opposed to database - username
and so on) that is local to each database session. It needs to be
visible from within plpgsql trigger functions and will be used
on a large fraction of updates.
I can see a few ways of doing it, none of them terribly pretty:
Keep all the data in a globally visible table, indexed by the
PID of the database backend.
Create a temporary table at the beginning of each session containing
the data, and simply read it out of that, relying on the temporary
table to be session-local.
Anyone have a suggestion for something that's either prettier, lower
overhead or both?
Cheers,
Steve
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives? http://archives.postgresql.org 8 1979
Steve Atkins wrote: I need to keep a small amount of information (things like a unique session identifier, the application - as opposed to database - username and so on) that is local to each database session. It needs to be visible from within plpgsql trigger functions and will be used on a large fraction of updates.
Create a temporary table at the beginning of each session containing the data, and simply read it out of that, relying on the temporary table to be session-local.
This is exactly how you should do it.
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)
Steve Atkins wrote: I need to keep a small amount of information (things like a unique session identifier, the application - as opposed to database - username and so on) that is local to each database session. It needs to be visible from within plpgsql trigger functions and will be used on a large fraction of updates.
Create a temporary table at the beginning of each session containing the data, and simply read it out of that, relying on the temporary table to be session-local.
This is exactly how you should do it.
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)
Steve Atkins wrote: I have an application where each user session opens and maintains a long-lived connection to the postgresql backend database.
I need to keep a small amount of information (things like a unique session identifier, the application - as opposed to database - username and so on) that is local to each database session. It needs to be visible from within plpgsql trigger functions and will be used on a large fraction of updates.
I can see a few ways of doing it, none of them terribly pretty:
Keep all the data in a globally visible table, indexed by the PID of the database backend.
Create a temporary table at the beginning of each session containing the data, and simply read it out of that, relying on the temporary table to be session-local.
Anyone have a suggestion for something that's either prettier, lower overhead or both?
One way to do this is to write a C-language function to set a global
variable and another to read from that variable. I.e. write a:
void setCookie(text) ;
text getCookie();
pair, invoking setCookie() upon connecting to the database.
There are three problems with using PostgreSQL temporary tables:
1. PL/pgSQL will cache the OID of the temporary table that existed
when it is first parsed, and when that temporary table is dropped
and recreated later, despite having the same name and structure,
you'll get an error like:
ERROR: relation with OID 869140 does not exist
CONTEXT: PL/pgSQL function "mytest" line 4 at select into variables
The work-around is to use EXECUTE to build the query string at
run-time.
2. For the same reason as above, you cannot build views against the
session-local temporary table. However, you could write a wrapper
PL/pgSQL function that leverages EXECUTE and use that wrapper
function in your view definition.
3. Under pre-7.4 databases, the large number of temporary table
creations/drops caused system catalog index bloat, which required
occassional REINDEXing under a stand-alone postgres backend. Under
7.4's index reuse, that seems to have abated.
You can build both PL/pgSQL functions and VIEWs against your 'C'
functions though. I suspect performance would be better, but you'd
have to do some testing. In the long run, I assume PostgreSQL will
one day have SQL temporary tables (whose structure persists across
sessions but whose content does not) which will ultimately be the
correct solution. Until then, it's a matter of preference and
hoop-jumping depending upon server version...
HTH,
Mike Mascari
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org
Steve Atkins wrote: I have an application where each user session opens and maintains a long-lived connection to the postgresql backend database.
I need to keep a small amount of information (things like a unique session identifier, the application - as opposed to database - username and so on) that is local to each database session. It needs to be visible from within plpgsql trigger functions and will be used on a large fraction of updates.
I can see a few ways of doing it, none of them terribly pretty:
Keep all the data in a globally visible table, indexed by the PID of the database backend.
Create a temporary table at the beginning of each session containing the data, and simply read it out of that, relying on the temporary table to be session-local.
Anyone have a suggestion for something that's either prettier, lower overhead or both?
One way to do this is to write a C-language function to set a global
variable and another to read from that variable. I.e. write a:
void setCookie(text) ;
text getCookie();
pair, invoking setCookie() upon connecting to the database.
There are three problems with using PostgreSQL temporary tables:
1. PL/pgSQL will cache the OID of the temporary table that existed
when it is first parsed, and when that temporary table is dropped
and recreated later, despite having the same name and structure,
you'll get an error like:
ERROR: relation with OID 869140 does not exist
CONTEXT: PL/pgSQL function "mytest" line 4 at select into variables
The work-around is to use EXECUTE to build the query string at
run-time.
2. For the same reason as above, you cannot build views against the
session-local temporary table. However, you could write a wrapper
PL/pgSQL function that leverages EXECUTE and use that wrapper
function in your view definition.
3. Under pre-7.4 databases, the large number of temporary table
creations/drops caused system catalog index bloat, which required
occassional REINDEXing under a stand-alone postgres backend. Under
7.4's index reuse, that seems to have abated.
You can build both PL/pgSQL functions and VIEWs against your 'C'
functions though. I suspect performance would be better, but you'd
have to do some testing. In the long run, I assume PostgreSQL will
one day have SQL temporary tables (whose structure persists across
sessions but whose content does not) which will ultimately be the
correct solution. Until then, it's a matter of preference and
hoop-jumping depending upon server version...
HTH,
Mike Mascari
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org
On Mon, May 03, 2004 at 02:18:28PM -0400, Mike Mascari wrote: I wrote:
There are three problems with using PostgreSQL temporary tables:
1. PL/pgSQL will cache the OID of the temporary table that existed when it is first parsed, and when that temporary table is dropped and recreated later, despite having the same name and structure, you'll get an error like:
ERROR: relation with OID 869140 does not exist CONTEXT: PL/pgSQL function "mytest" line 4 at select into variables
The work-around is to use EXECUTE to build the query string at run-time.
I should point out that if you ensure that you create the temporary table before invoking the function, the function gets parsed once after the first invocation at the beginning of the session. So that, in that instance, it would be okay.
OK, sounds like that'll work nicely for the particular application I'm
working on. Thanks.
Cheers,
Steve
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
On Mon, May 03, 2004 at 02:18:28PM -0400, Mike Mascari wrote: I wrote:
There are three problems with using PostgreSQL temporary tables:
1. PL/pgSQL will cache the OID of the temporary table that existed when it is first parsed, and when that temporary table is dropped and recreated later, despite having the same name and structure, you'll get an error like:
ERROR: relation with OID 869140 does not exist CONTEXT: PL/pgSQL function "mytest" line 4 at select into variables
The work-around is to use EXECUTE to build the query string at run-time.
I should point out that if you ensure that you create the temporary table before invoking the function, the function gets parsed once after the first invocation at the beginning of the session. So that, in that instance, it would be okay.
OK, sounds like that'll work nicely for the particular application I'm
working on. Thanks.
Cheers,
Steve
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
I wrote: There are three problems with using PostgreSQL temporary tables:
1. PL/pgSQL will cache the OID of the temporary table that existed when it is first parsed, and when that temporary table is dropped and recreated later, despite having the same name and structure, you'll get an error like:
ERROR: relation with OID 869140 does not exist CONTEXT: PL/pgSQL function "mytest" line 4 at select into variables
The work-around is to use EXECUTE to build the query string at run-time.
I should point out that if you ensure that you create the temporary
table before invoking the function, the function gets parsed once
after the first invocation at the beginning of the session. So that,
in that instance, it would be okay.
Mike Mascari
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
I wrote: There are three problems with using PostgreSQL temporary tables:
1. PL/pgSQL will cache the OID of the temporary table that existed when it is first parsed, and when that temporary table is dropped and recreated later, despite having the same name and structure, you'll get an error like:
ERROR: relation with OID 869140 does not exist CONTEXT: PL/pgSQL function "mytest" line 4 at select into variables
The work-around is to use EXECUTE to build the query string at run-time.
I should point out that if you ensure that you create the temporary
table before invoking the function, the function gets parsed once
after the first invocation at the beginning of the session. So that,
in that instance, it would be okay.
Mike Mascari
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: roberto3214 |
last post by:
Hi Guys,
How are you? I have recently begun some testing on IIS 6.0 in regards
to an asp.net application. After lots of testing I decided to create a
simple 1k page size webpage to find out whats the max rps I can
achieve. So I installed Microsoft Application Stress Tool (WAS) and
started testing. I setup basic 2 tests page does no processing
whatsoever:
TEST 1
|
by: Kallis |
last post by:
Hello,
I have the following situation when trying to localize my software:
I have BIG solution with about 80 projects. In one of the projects I
have a number of dialogs (the dialog project :-) ). I have decided
that I do not want to use the "form"-mechanism (using the property
"localized=true") for localization since the strings I show are not
that "constant" during the life time of the dialog. Thus, I have to
put the resources in...
|
by: Rob Nicholson |
last post by:
We're using a well known presentation layer library to implement complex
controls on an intranet site. IE has the following limitation which
effectively means that you can only have 30 <STYLE> tags per page. That's in
effect 30 style sheets per page, not classes - each sheet can have as many
style classes as you want.
http://support.microsoft.com/default.aspx?scid=kb;en-us;262161
Unfortunately, this presentation library generates...
|
by: needin4mation |
last post by:
Hi, I have to decide between a per device and a per license issue. We
have several web services that have functions that use things like
LOGON_USER. If I have a per device license, does that mean things like
LOGON_USER go away? Or that I cannot use Windows Integrated
Authentication for UNC file server stuff, web pages, etc.? Thank you.
|
by: Karl O. Pinc |
last post by:
Hi,
I don't suppose that the todo item:
Referential Integrity
o Add deferred trigger queue file (Jan)
Means that there will be a statement like:
CREATE TRIGGER ... FOR EACH TRANSACTION
| |
by: bruno at modulix |
last post by:
Hi
I'm currently playing with some (possibly weird...) code, and I'd have a
use for per-instance descriptors, ie (dummy code):
class DummyDescriptor(object):
def __get__(self, obj, objtype=None):
if obj is None:
return self
return getattr(obj, 'bar', 'no bar')
|
by: Matias Jansson |
last post by:
I come from a background of Java and C# where it is common practise to have
one class per file in the file/project structure. As I have understood it,
it is more common practice to have many classes in a Python module/file.
What is the motivation behind it, would it be a bad idea to have a guideline
in your project that promotes a one class per file structure (assuming most
of the programmers a background similar to mine)?
|
by: Joseph Geretz |
last post by:
I need to calculate miles per degree longitude, which obviously depends on
latitude since lines of longitude converge at the poles. Via Google, I've
come up with the following calculation:
private const double MilesPerDegLat = 69.04;
private const double EarthRadiusMiles = 3963.1676;
private static double PiDiv180 = Math.PI / 180;
double MilesPerDegLon = MilesPerDegLat * Math.Cos(Latitude * PiDiv180)
|
by: bakxchaixDD |
last post by:
I DON'T GET THIS
project:
Many treadmills output the speed in miles per hour. However, most runners think of their pace in minutes and seconds per mile. Write a program that inputs a decimal value for miles per hour and converts the value to minutes and seconds per mile.
Sample input, output:
For input 5.5 mph, the output should be 10 minutes and 55 seconds per mile.
For input 4 mph, the output should be 15 minutes and 0 seconds...
|
by: raveekumarg |
last post by:
hi
what is the difference between per seat , per server , per processor and i am new to sql 2000 , pl do explain the same.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |