How to time several queries?

Started by Nonameover 21 years ago6 messagesgeneral
Jump to latest
#1Noname
nd02tsk@student.hig.se

Hello

I know it is possible to time isolated queries through the settting of the
\timing option in psql. This makes PgSQL report the time it took to
perform one operation.

I would like to know how one can get a time summary of many operations, if
it is at all possible.

Thank you.

Tim

#2Ken Tozier
kentozier@comcast.net
In reply to: Noname (#1)
Superuser log-in through a web interface?

Hello all,

I'm trying to create a php form for logging in to postgress with
different level passwords and my first test with a superuser isn't
working unless I specify a database name. I would like to allow
superusers to log in without specifying a database so they can create
new users, databases etc from a web interface. Does anyone see what I'm
doing wrong in the following example?

Thanks for any help,

Ken

---------------------------------------------
I defined a super user like so

CREATE USER user_name CREATEUSER PASSWORD 'password'

Try to log in through a web form like so:

User: user_name
Password: password

but the connection always fails unless I specify a database.

Relevant PHP:

<?php

function LogInUser()
{
if (isset($_POST['user_name']) &&
isset($_POST['password']))
{
$user = $_POST['user_name'];
$password = $_POST['password'];

$conn_string = "user=".$user." password=".$password." host=localhost
port=5432";
$conn = pg_connect($conn_string);

if ($conn)
{
echo "login succeeded";
}
}
}
?>

#3Kevin Barnard
kevin.barnard@gmail.com
In reply to: Ken Tozier (#2)
Re: Superuser log-in through a web interface?

You have a conceptual error. When connecting you are connecting "to a
database". With out the database you are not connecting to anything
hence the failure.

Typically to do what you are trying to do you would connect to the
database template1 unless a database is specified. If you have
another DB you can connect to that and do your create commands there
are well.

Show quoted text

On Sat, 30 Oct 2004 20:35:50 -0400, Ken Tozier <kentozier@comcast.net> wrote:

Hello all,

I'm trying to create a php form for logging in to postgress with
different level passwords and my first test with a superuser isn't
working unless I specify a database name. I would like to allow
superusers to log in without specifying a database so they can create
new users, databases etc from a web interface. Does anyone see what I'm
doing wrong in the following example?

Thanks for any help,

Ken

---------------------------------------------
I defined a super user like so

CREATE USER user_name CREATEUSER PASSWORD 'password'

Try to log in through a web form like so:

User: user_name
Password: password

but the connection always fails unless I specify a database.

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

#4Ken Tozier
kentozier@comcast.net
In reply to: Kevin Barnard (#3)
Re: Superuser log-in through a web interface?

On Oct 31, 2004, at 1:29 AM, Kevin Barnard wrote:

You have a conceptual error. When connecting you are connecting "to a
database". With out the database you are not connecting to anything
hence the failure.

That explains it, thanks.

Another pesky problem I've run into is that I can enter literally
anything into the user name and password fields of my php form and it
still logs in. What's up with that? Is there some way find out the user
for a given connection?

I tried to use pg_user and pg_shadow but neither of them registered as
valid functions in the PHP code.

In reply to: Ken Tozier (#4)
Re: Superuser log-in through a web interface?

On Sun, Oct 31, 2004 at 05:24:34AM -0500, Ken Tozier wrote:

On Oct 31, 2004, at 1:29 AM, Kevin Barnard wrote:

You have a conceptual error. When connecting you are connecting "to a
database". With out the database you are not connecting to anything
hence the failure.

That explains it, thanks.

Another pesky problem I've run into is that I can enter literally
anything into the user name and password fields of my php form and it
still logs in. What's up with that? Is there some way find out the user
for a given connection?

This is probably because pg_hba.conf settings. By default, it trusts
connections from localhost, which means that any connection being made
from localhost (which is the case when the web server and database are
running in the same machine) will be accepted regardless of user and password.

You should change these lines in pg_hba.conf

local all all trust
# IPv4-style local connections:
host all all 127.0.0.1/32 trust

and change 'trust' to your preferred auth method (password, md5, etc.)

Check out the docs for authentication methods at
http://www.postgresql.org/docs/7.4/interactive/client-authentication.html

HTH,
--
Vinko Vrsalovic <el[|-@-|]vinko.cl>

#6Ken Tozier
kentozier@comcast.net
In reply to: Vinko Vrsalovic (#5)
Re: Superuser log-in through a web interface?

On Oct 31, 2004, at 12:40 PM, Vinko Vrsalovic wrote:

<snip>

This is probably because pg_hba.conf settings. By default, it trusts
connections from localhost, which means that any connection being made
from localhost (which is the case when the web server and database are
running in the same machine) will be accepted regardless of user and
password.

You should change these lines in pg_hba.conf

local all all trust
# IPv4-style local connections:
host all all 127.0.0.1/32 trust

and change 'trust' to your preferred auth method (password, md5, etc.)

Check out the docs for authentication methods at
http://www.postgresql.org/docs/7.4/interactive/client-
authentication.html

Thanks Vinko that did the trick.

Ken