bilak
bilak

Reputation: 4966

postgresql unable to create table in schema

I'm creating schema/db/... with this script:

CREATE ROLE testuser LOGIN PASSWORD 'password';
CREATE TABLESPACE testtablespace OWNER testuser LOCATION '/pgdata/pg94/testtablespace';
CREATE SCHEMA testschema;
ALTER SCHEMA testschema OWNER TO testuser;
CREATE DATABASE testdb WITH TABLESPACE testtablespace ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0 OWNER testuser;
ALTER DATABASE testdb SET search_path TO testschema, public;
ALTER ROLE testuser SET search_path TO testschema, public;
GRANT ALL ON DATABASE testdb TO testuser;
GRANT ALL ON SCHEMA testschema TO testuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA testschema TO testuser;
ALTER ROLE testuser SET default_tablespace = testtablespace;

when I log in with command psql -U testuser testdb and execute comand select schema_name from information_schema.schemata ;. What is worse I can't create table within this schema

testdb=> create table testschema.test (test varchar(10));
ERROR:  schema "testschema" does not exist

please what should I configure to view schema and also create tables in int?

Upvotes: 2

Views: 3682

Answers (1)

klin
klin

Reputation: 121889

CREATE SCHEMA always applies to current database. You have created testschema in current database (probably postgres), not in testdb. You should connect to testdb and then create new schemas.

Upvotes: 2

Related Questions