pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sivapostgres@yahoo.com <sivapostgres@yahoo.com>
To: Pgsql-general General <pgsql-general@postgresql.org>
Subject: Re: Need to find the no. of connections for a database
Date: Thu, 27 Feb 2020 11:35:51 +0000 (UTC)
Message-ID: <1654972450.2631031.1582803351218@mail.yahoo.com> (raw)
In-Reply-To: <C06A448C-51BC-43B9-A0CF-558F28E0090E@gmx.com>
References: <1393516227.2562442.1582789296867.ref@mail.yahoo.com>
	<1393516227.2562442.1582789296867@mail.yahoo.com>
	<C06A448C-51BC-43B9-A0CF-558F28E0090E@gmx.com>

 Well,
I need to prevent other users from entering any transaction till I finish taking reports from my application.  All users will be using the same application, from which this report is supposed to be printed.  
If they enter any data, those data also need to be taken into account in this report.   The process is somehow lengthy that starts from arriving some cumulative value(s) and based on this value, some lengthy process is done.  Any data entered in between will affect this report as well the process we do.  
For this same situation, while using SQL Server, we used to count the number of users of that database and if it's greater than one, we don't start the process.  By checking the same no. of users in vantage point, we could achieve the required result.
I tried the same way in Postgres, but I could not get the correct connection list, by using this query.
SELECT pid, datname, usename, application_name, client_hostname, client_port, backend_start, query_start, query, stateFROM pg_stat_activityWHERE datname = 'databasename'And   state = 'active'
I expect this query to add the number, when there is another connection from one computer.  I couldn't get it when I tried this query from PGAdmin and connected this database from another machine.  It's just a connection and no query was executed from that machine.
I think setting isolation level will not work out. Switching to single user mode, if available, will be better.  
Any ideas ?
Happiness AlwaysBKR Sivaprakash
    On Thursday, 27 February, 2020, 04:34:46 pm IST, Ravi Krishna <srkrishna@gmx.com> wrote:  
 
 > 
> Before taking a few reports, we need to ensure that only one connection is made to the database and all other computers need to close the connection to that database.  This is to prevent any additional entry(ies) that could be made during the course of the report taking.  This single-user mode is to be there till the report is taken and few entries are passed.  
> 
> How to do it?    Is it possible to switch to single-user mode from application and back to multi-user mode once the work is completed?  Or any other solution available?
> 
> Happiness Always
> BKR Sivaprakash
> 

This concept is outdated.  You should set your application to correct isolation level to get a consistent state.
  

view thread (14+ messages)  latest in thread

Message-ID: <1654972450.2631031.1582803351218@mail.yahoo.com>
Permalink:  ../1654972450.2631031.1582803351218@mail.yahoo.com/
Also on:    postgresql.org/message-id/1654972450.2631031.1582803351218@mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: sivapostgres@yahoo.com
  Subject: Re: Need to find the no. of connections for a database
  In-Reply-To: <1654972450.2631031.1582803351218@mail.yahoo.com>
  References: <1393516227.2562442.1582789296867.ref@mail.yahoo.com> <1393516227.2562442.1582789296867@mail.yahoo.com> <C06A448C-51BC-43B9-A0CF-558F28E0090E@gmx.com> <1654972450.2631031.1582803351218@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox