\! gs_ktool -d all
DELETE ALL

\! gs_ktool -g
GENERATE
1
\! gs_ktool -g
GENERATE
2
DROP CLIENT MASTER KEY IF EXISTS MyCMK CASCADE;
NOTICE:  client master key "mycmk" does not exist
DROP CLIENT MASTER KEY testns.MyCMKt CASCADE;
ERROR:  schema "testns" does not exist
CREATE CLIENT MASTER KEY MyCMK WITH ( KEY_STORE = gs_ktool , KEY_PATH = "gs_ktool/1" , ALGORITHM = AES_256_CBC);
CREATE COLUMN ENCRYPTION KEY MyCEK WITH VALUES (CLIENT_MASTER_KEY = MyCMK, ALGORITHM = AEAD_AES_256_CBC_HMAC_SHA256);
CREATE TABLE tbl2 (b int, c int  ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = public.MyCEK, ENCRYPTION_TYPE = DETERMINISTIC), d int  ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = public.MyCEK, ENCRYPTION_TYPE = DETERMINISTIC));
CREATE SCHEMA testns;
CREATE CLIENT MASTER KEY testns.MyCMKt WITH ( KEY_STORE = gs_ktool , KEY_PATH = "gs_ktool/2" , ALGORITHM = AES_256_CBC);
CREATE COLUMN ENCRYPTION KEY testns.MyCEK WITH VALUES (CLIENT_MASTER_KEY = testns.MyCMKt, ALGORITHM = AEAD_AES_256_CBC_HMAC_SHA256);
SET search_path to testns;
CREATE COLUMN ENCRYPTION KEY MyCEK2 WITH VALUES (CLIENT_MASTER_KEY = testns.MyCMKt, ALGORITHM = AEAD_AES_256_CBC_HMAC_SHA256);
CREATE COLUMN ENCRYPTION KEY MyCEK3 WITH VALUES (CLIENT_MASTER_KEY = public.MyCMK, ALGORITHM = AEAD_AES_256_CBC_HMAC_SHA256);
CREATE TABLE tbl2 (b int, c int  ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = public.MyCEK, ENCRYPTION_TYPE = DETERMINISTIC), d int  ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = public.MyCEK, ENCRYPTION_TYPE = DETERMINISTIC));
SET search_path to testns, public;
SELECT d FROM tbl2 WHERE c = 1;
 d 
---
(0 rows)

DROP TABLE tbl2;
DROP SCHEMA testns;
ERROR:  cannot drop schema testns because other objects depend on it
DETAIL:  client master key: mycmkt depends on schema testns
column encryption key: mycek depends on schema testns
column encryption key: mycek2 depends on schema testns
column encryption key: mycek3 depends on schema testns
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
DROP SCHEMA testns CASCADE;
NOTICE:  drop cascades to 4 other objects
DETAIL:  drop cascades to client master key: mycmkt
drop cascades to column encryption key: mycek
drop cascades to column encryption key: mycek2
drop cascades to column encryption key: mycek3
DROP TABLE tbl2;
DROP CLIENT MASTER KEY MyCMK CASCADE;
NOTICE:  drop cascades to column encryption key: mycek
\! gs_ktool -d all
DELETE ALL
 1 2