Database Oid from SPI

Started by Markus Wannerover 19 years ago5 messagesgeneral
Jump to latest
#1Markus Wanner
markus@bluegap.ch

Hi,

how can I get the database name or OID of the current backend in a SPI
function (in plain C)? I tried including storage/proc.h and accessing
MyProc->databaseId, but that leads to a segfault :-( (and seems like
the wrong way to do it.)

The SPI documentation didn't help.

Thank you

Markus

#2Markus Wanner
markus@bluegap.ch
In reply to: Markus Wanner (#1)
Re: Database Oid from SPI

Whoops, sorry, there was another reason for the segfault. Using
MyProc->databaseId works. Is it the right way to do it, though?

Markus Schiltknecht wrote:

Show quoted text

Hi,

how can I get the database name or OID of the current backend in a SPI
function (in plain C)? I tried including storage/proc.h and accessing
MyProc->databaseId, but that leads to a segfault :-( (and seems like
the wrong way to do it.)

The SPI documentation didn't help.

Thank you

Markus

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Markus Wanner (#2)
Re: Database Oid from SPI

Markus Schiltknecht wrote:

Whoops, sorry, there was another reason for the segfault. Using
MyProc->databaseId works. Is it the right way to do it, though?

I'd use MyDatabaseId ...

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Markus Wanner (#2)
Re: Database Oid from SPI

Markus Schiltknecht <markus@bluegap.ch> writes:

Whoops, sorry, there was another reason for the segfault. Using
MyProc->databaseId works. Is it the right way to do it, though?

Actually I'd recommend you use the global MyDatabaseId from
"miscadmin.h". It'll be the same value, but it's always best
to avoid unnecessary accesses to shared memory.

regards, tom lane

#5Markus Wanner
markus@bluegap.ch
In reply to: Tom Lane (#4)
Re: Database Oid from SPI

Hi,

thank you both. I first tried that, but the segfault really irritated
me. It's now working fine with miscadmin.h. Sorry for the noise.

Regards

Markus

Tom Lane wrote:

Actually I'd recommend you use the global MyDatabaseId from
"miscadmin.h". It'll be the same value, but it's always best
to avoid unnecessary accesses to shared memory.

regards, tom lane

Alvaro Herrera wrote:

Show quoted text

I'd use MyDatabaseId ...