You should not only grant privileges on the database (CTc
means the user can connect to the database and create new and temp databases), but also on the database objects.
GRANT ROLE
The absolutely easiest way to do this is to grant the owner role to the phpuser
role:
GRANT owner_role TO phpuser;
This may, however, introduce all manner of security problems and is not generally recommended for any scenario unless you are very confident about your network security.
GRANT privilege
Now for the hard way.
To begin with, your phpuser
most likely does not have to create new or temporary database, so revoke these privileges:
REVOKE CREATE, TEMP ON DATABASE mydatabase FROM phpuser;
If you have tables or other objects in schemas other than public
, grant access to those schemas (you need to be connected to database mydatabase
when you issue these commands):
GRANT USAGE ON SCHEMA myschema TO phpuser;
Now you can grant the privileges to all tables, sequences, functions, etc inside the schemas, so for each schema, including public
, do:
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA myschema TO phpuser;
GRANT ALL ON ALL SEQUENCES IN SCHEMA myschema TO phpuser;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA myschema TO phpuser;
If you have some more exotic objects, use the appropriate command. Views are included in the table grant and indexes are automatically included with the tables.
Network access
Note that the phpuser
role should also be permitted access in the pg_hba.conf
file. There should be a line like (modify to match your network configuration):
host mydatabase phpuser 127.0.0.1/32 md5