Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j7HTL-0002ak-3U for pgsql-general@arkaria.postgresql.org; Thu, 27 Feb 2020 11:36:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j7HTJ-0008PA-NB for pgsql-general@arkaria.postgresql.org; Thu, 27 Feb 2020 11:36:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j7HTI-0008P3-Rw for pgsql-general@lists.postgresql.org; Thu, 27 Feb 2020 11:36:53 +0000 Received: from sonic312-19.consmr.mail.sg3.yahoo.com ([106.10.244.209]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j7HTB-0008Pm-JM for pgsql-general@postgresql.org; Thu, 27 Feb 2020 11:36:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1582803400; bh=qg5bA0yXpSX6LuGny5Xx4MxFxGAhKRbyw55HMoRUezc=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=JrT9yCTugbiNuWEcxndQ8t1Mtl/ZxMfXSAjLHT/8IPd+cwUuWl/nQd2J5rBgI60IBQs9/w602PUMIVBA/elL7tyt+XozV4zBVx0mgDGRFKFN19SAKoRhD+gT3N9qjPvDsLP2Ls2SnufvmZwWWwB2Y+bYM1pwqBOdWF+cyZYM3wucdxKX3Lxi/JxJi0Zu8ysmQ/eup5wf88gam959MTU9bxFp4YUZes4tIBpPyzy5CbXMBssNncgrp8VfA39HBvgulZDx40Nxd5CmwZHR0nsh88iGY3jk7NY9E+j3C1Zl+A+tgvSpC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g6frpNF3o4uZpkPI9ZMgZjZWc9Q Ix8AwqNIDiLUhbqMQDMWH6fIdbiglgN56ffIMGybldvi1vkpx0frI.ajowU7S7G2K0g1P.EChJYU hChRYz0iVGQ2sPOlwgaS22Zyvq8dcMoCQqGQTVPQDiEL0C.IKp6gDNmPifKK0wZUeTeS5gM7e0fz Q.6q9Mv.2AyK1HOu3CZNg68r82.6xe6v_Fd2ZRwlJT0YjhP.NpEZN7UWSZRA7HK456N0lvPtS.Fa .GulBOjtObFXw1_ksL8cMPEMGDqtxQ3jkSDPCXdS3F4oXWRQWYffaz52O8UqE.osW.tIDf4jnnUu vxK7kfJTmOLkpE4T4HBwHE1C9ay_QI8Vzz5B5EIz.9CEoJjvOE_BhjSzLO1FP6Ba_TT_BFgb2pzG C0D.ZiFS_MxE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.sg3.yahoo.com with HTTP; Thu, 27 Feb 2020 11:36:40 +0000 Received: by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 34fe2a14a86c3b7dfd86976014f73efa; Thu, 27 Feb 2020 11:36:39 +0000 (UTC) X-YMail-OSG: ubAW2O4VM1k8unjCndh.MDSCTa9T9vGPrDIHOAsP8Zuw.CvXQwzNbUv101ML6Kk xewT.XTpn7C..UQ6aKDxevnIDonnuTghvgjqAKfHzfEVvu_mFL9mO..YR1W0JMWnftej0DdZm21Q glExuV9aJs3gPWhpjNh21K8JNdqWAsAXdR.qrJNOLSKbSqOXq3kFFH9hDf3oUk00FLri77.J0VsZ TdgVVZMhHO.SI.wlsAtRYtfgWXqmGEJBrJAfmIU4E1SqgzOqicX2z0ih1a1DmRyzPjq7Y9ENUz2i R5dAec4IAAUeCxZ25zMs.4y4KOSHPlv6ZnKJYw.Z8Eg6u7ewA4nlk4q27AEAWQTtFUbmos4vsOxO aWPMpv_X3TtjBoRPXdKJaFEJ5nySg5HJIV.AmF9GZpSPXv4uknv50n9_.KGwB4dTia1KOagY.Sb9 9c39gtsPtEDiCr.9jANB2u9fTO0NInxZlF_nCm8KauUJIAdcd3322hjjtFQvfNPPQBa6F6NLYGrc MYgTPZ_HBF0bvPsKxxyGttThkMUCg6KsjD7tY4auiqoBiDg_syFEaaesasboXNT8Z0K3qwA805MG 5a2JWcK2mNtTnNTWuQgAL7AxhbdDZCnx2J5Z.FlSYf90nexPCgwCnWQL2UuqEx1iJaV.Qv5RZLQ4 2wLE3.mpp1VHVjptURZV9Slbb_Gt6Vm9WM5bauiYXXPOU2Gje9X2NFW8wE1sYF.Tq0HQ6rZZY7Yu jBCKUIx7XgPSMYjM2EQc7hITDoMFN5iewA2gZ4PArASYWzQRiCMXtXvzi.zz15k7wS6AwwWKiuE4 jo1LPN4_6NGwwMu.71Lj714CSg9al1yz8JoOy_PDJfDo64Dfc8syDVlssaeizTsKsa7_e2NFTq4Z 22xTD0bbVN0TPH3Vfm_AttiwmvlGfdmNEP47.DRsgOZDOrVPFAVOcgf9Ay4sI7CEd.KdM9EVNj2P jeiNl.uf96cvCgcdGxIz3msEb1yVNBCTSrgchDdaM3sJtgTz.vLKzpAYaHXTaTlYnQWXEvlLmfbq SCgowtwlEXx8DN29A0wQVMQ2gK0OgG9fKqk3hjbXMLOJbBBfJurYJdkhLVBsAtjXCQYWbXOQ68jE OZCKTjyqHIf.q_qkz2kKqZywIUHsPe63bUhkE9MnnTvMzvVFrK2AcAqHzuSa_no2RKk0ircBw8JF C5FgJLiUlq99Wz9nTuXKQVdbprqZmmmHzW6TCW0s3gkr1zXFiBPPc.rgy9KmUEkKZTAitgv1_eBP qUa3e.7cJVpZW3MgXcEx8Qr9e.prdp3_LhA0eEDUu4LOW10p6I8X.2jQMPELijMDm Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 27 Feb 2020 11:36:37 +0000 Date: Thu, 27 Feb 2020 11:35:51 +0000 (UTC) From: "sivapostgres@yahoo.com" Reply-To: "sivapostgres@yahoo.com" To: Pgsql-general General Message-ID: <1654972450.2631031.1582803351218@mail.yahoo.com> In-Reply-To: References: <1393516227.2562442.1582789296867.ref@mail.yahoo.com> <1393516227.2562442.1582789296867@mail.yahoo.com> Subject: Re: Need to find the no. of connections for a database MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2631030_696744813.1582803351217" X-Mailer: WebService/1.1.15302 YMailNorrin Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36 Content-Length: 7170 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_2631030_696744813.1582803351217 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Well, I need to prevent other users from entering any transaction till I finish t= aking reports from my application.=C2=A0 All users will be using the same a= pplication, from which this report is supposed to be printed.=C2=A0=C2=A0 If they enter any data, those data also need to be taken into account in th= is report.=C2=A0 =C2=A0The process is somehow lengthy that starts from arri= ving some cumulative value(s) and based on this value, some lengthy process= is done.=C2=A0 Any data entered in between will affect this report as well= the process we do.=C2=A0=C2=A0 For this same situation, while using SQL Server, we used to count the numbe= r of users of that database and if it's greater than one, we don't start th= e process.=C2=A0 By checking the same no. of users in vantage point, we cou= ld achieve the required result. I tried the same way in Postgres, but I could not get the correct connectio= n list, by using this query. SELECT pid, datname, usename, application_name, client_hostname, client_por= t, backend_start, query_start, query, stateFROM pg_stat_activityWHERE datna= me =3D 'databasename'And=C2=A0 =C2=A0state =3D 'active' I expect this query to add the number, when there is another connection fro= m one computer.=C2=A0 I couldn't get it when I tried this query from PGAdmi= n and connected this database from another machine.=C2=A0 It's just a conne= ction 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.=C2=A0=C2=A0 Any ideas ? Happiness AlwaysBKR Sivaprakash On Thursday, 27 February, 2020, 04:34:46 pm IST, Ravi Krishna wrote: =20 =20 >=20 > Before taking a few reports, we need to ensure that only one connection i= s made to the database and all other computers need to close the connection= to that database.=C2=A0 This is to prevent any additional entry(ies) that = could be made during the course of the report taking.=C2=A0 This single-use= r mode is to be there till the report is taken and few entries are passed.= =C2=A0=20 >=20 > How to do it?=C2=A0 =C2=A0 Is it possible to switch to single-user mode f= rom application and back to multi-user mode once the work is completed?=C2= =A0 Or any other solution available? >=20 > Happiness Always > BKR Sivaprakash >=20 This concept is outdated.=C2=A0 You should set your application to correct = isolation level to get a consistent state. =20 ------=_Part_2631030_696744813.1582803351217 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Well,

I ne= ed to prevent other users from entering any transaction till I finish takin= g reports from my application.  All users will be using the same appli= cation, 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 sta= rts from arriving some cumulative value(s) and based on this value, some le= ngthy process is done.  Any data entered in between will affect this r= eport as well the process we do.  

For this sam= e situation, while using SQL Server, we used to count the number of users o= f that database and if it's greater than one, we don't start the process.&n= bsp; By checking the same no. of users in vantage point, we could achieve t= he required result.

<= div dir=3D"ltr" data-setdir=3D"false">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, state
= FROM pg_stat_activity
WHERE datname =3D 'databasename'
= And   state =3D '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 connecte= d this database from another machine.  It's just a connection and no q= uery was executed from that machine.

I think setting isol= ation level will not work out. Switching to single user mode, if available,= will be better.  
Any ideas ?

Happiness Always
BKR Sivaprak= ash

=20
=20
On Thursday, 27 February, 2020, 04:34:46 pm IST, Ravi K= rishna <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 c= omputers need to close the connection to that database.  This is to p= revent any additional entry(ies) that could be made during the course of th= e 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 sin= gle-user mode from application and back to multi-user mode once the work is= completed?  Or any other solution available?
> <= br clear=3D"none">> Happiness Always
> BKR Sivaprak= ash

>

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

------=_Part_2631030_696744813.1582803351217--