Paul M Foster <paulf(at)quillandmouse(dot)com> writes:
>> What is the exact error you're getting in the C program?
> ERROR: CREATE DATABASE: source database "template1" is being accessed by
> other users
Please note this is CREATE DATABASE complaining, *not* connection
establishment. You can't create a database by cloning an open database
(there are not locks that would make this safe). Either don't use
template1 for normal operations, or use template0 as the template for
CREATE DATABASE.
regards, tom lane