Skip to main content

Hive "drop table" hangs (Postgres Metastore)

Listen:
By using postgres as a metastore database it could be happen that "drop table xyz" hangs and Postgres is showing LOCKS with UPDATE. This happen since some tables are missing and can be fixed by using:

create index "IDXS_FK1" on "IDXS" using btree ("SD_ID");
create index "IDXS_FK2" on "IDXS" using btree ("INDEX_TBL_ID");
create index "IDXS_FK3" on "IDXS" using btree ("ORIG_TBL_ID");

CREATE TABLE "ROLES" (
"ROLE_ID" bigint NOT NULL,
"CREATE_TIME" int NOT NULL,
"OWNER_NAME" varchar(128) DEFAULT NULL,
"ROLE_NAME" varchar(128) DEFAULT NULL,
PRIMARY KEY ("ROLE_ID"),
CONSTRAINT "ROLEENTITYINDEX" UNIQUE ("ROLE_NAME")
) ;

CREATE TABLE "ROLE_MAP" (
"ROLE_GRANT_ID" bigint NOT NULL,
"ADD_TIME" int NOT NULL,
"GRANT_OPTION" smallint NOT NULL,
"GRANTOR" varchar(128) DEFAULT NULL,
"GRANTOR_TYPE" varchar(128) DEFAULT NULL,
"PRINCIPAL_NAME" varchar(128) DEFAULT NULL,
"PRINCIPAL_TYPE" varchar(128) DEFAULT NULL,
"ROLE_ID" bigint DEFAULT NULL,
PRIMARY KEY ("ROLE_GRANT_ID"),
CONSTRAINT "USERROLEMAPINDEX" UNIQUE ("PRINCIPAL_NAME","ROLE_ID","GRANTOR","GRANTOR_TYPE"),
CONSTRAINT "ROLE_MAP_FK1" FOREIGN KEY ("ROLE_ID") REFERENCES "ROLES" ("ROLE_ID")
) ;

CREATE TABLE "GLOBAL_PRIVS" (
"USER_GRANT_ID" bigint NOT NULL,
"CREATE_TIME" int NOT NULL,
"GRANT_OPTION" smallint NOT NULL,
"GRANTOR" varchar(128) DEFAULT NULL,
"GRANTOR_TYPE" varchar(128) DEFAULT NULL,
"PRINCIPAL_NAME" varchar(128) DEFAULT NULL,
"PRINCIPAL_TYPE" varchar(128) DEFAULT NULL,
"USER_PRIV" varchar(128) DEFAULT NULL,
PRIMARY KEY ("USER_GRANT_ID"),
CONSTRAINT "GLOBALPRIVILEGEINDEX" UNIQUE ("PRINCIPAL_NAME","PRINCIPAL_TYPE","USER_PRIV","GRANTOR","GRANTOR_TYPE")
) ;

CREATE TABLE "DB_PRIVS" (
"DB_GRANT_ID" bigint NOT NULL,
"CREATE_TIME" int NOT NULL,
"DB_ID" bigint DEFAULT NULL,
"GRANT_OPTION" smallint NOT NULL,
"GRANTOR" varchar(128) DEFAULT NULL,
"GRANTOR_TYPE" varchar(128) DEFAULT NULL,
"PRINCIPAL_NAME" varchar(128) DEFAULT NULL,
"PRINCIPAL_TYPE" varchar(128) DEFAULT NULL,
"DB_PRIV" varchar(128) DEFAULT NULL,
PRIMARY KEY ("DB_GRANT_ID"),
CONSTRAINT "DBPRIVILEGEINDEX" UNIQUE ("DB_ID","PRINCIPAL_NAME","PRINCIPAL_TYPE","DB_PRIV","GRANTOR","GRANTOR_TYPE"),
CONSTRAINT "DB_PRIVS_FK1" FOREIGN KEY ("DB_ID") REFERENCES "DBS" ("DB_ID")
) ;

CREATE TABLE "PART_PRIVS" (
"PART_GRANT_ID" bigint NOT NULL,
"CREATE_TIME" int NOT NULL,
"GRANT_OPTION" smallint NOT NULL,
"GRANTOR" varchar(128) DEFAULT NULL,
"GRANTOR_TYPE" varchar(128) DEFAULT NULL,
"PART_ID" bigint DEFAULT NULL,
"PRINCIPAL_NAME" varchar(128) DEFAULT NULL,
"PRINCIPAL_TYPE" varchar(128) DEFAULT NULL,
"PART_PRIV" varchar(128) DEFAULT NULL,
PRIMARY KEY ("PART_GRANT_ID"),
CONSTRAINT "PART_PRIVS_FK1" FOREIGN KEY ("PART_ID") REFERENCES "PARTITIONS" ("PART_ID")
) ;

create index "PARTPRIVILEGEINDEX" on "PART_PRIVS" using btree ("PART_ID","PRINCIPAL_NAME","PRINCIPAL_TYPE","PART_PRIV","GRANTOR","GRANTOR_TYPE");

CREATE TABLE "PART_COL_PRIVS" (
"PART_COLUMN_GRANT_ID" bigint NOT NULL,
"COLUMN_NAME" varchar(128) DEFAULT NULL,
"CREATE_TIME" int NOT NULL,
"GRANT_OPTION" smallint NOT NULL,
"GRANTOR" varchar(128) DEFAULT NULL,
"GRANTOR_TYPE" varchar(128) DEFAULT NULL,
"PART_ID" bigint DEFAULT NULL,
"PRINCIPAL_NAME" varchar(128) DEFAULT NULL,
"PRINCIPAL_TYPE" varchar(128) DEFAULT NULL,
"PART_COL_PRIV" varchar(128) DEFAULT NULL,
PRIMARY KEY ("PART_COLUMN_GRANT_ID"),
CONSTRAINT "PART_COL_PRIVS_FK1" FOREIGN KEY ("PART_ID") REFERENCES "PARTITIONS" ("PART_ID")
);

create index "PARTITIONCOLUMNPRIVILEGEINDEX" on "PART_COL_PRIVS" using btree ("PART_ID","COLUMN_NAME","PRINCIPAL_NAME","PRINCIPAL_TYPE","PART_COL_PRIV","GRANTOR","GRANTOR_TYPE")

Paste this into the pgsql CLI on your metastore database (psql -h <HOSTNAME> -d metastore -U hiveuser -W) and you should be able to drop tables.

Comments

Popular posts from this blog

Deal with corrupted messages in Apache Kafka

Under some strange circumstances, it can happen that a message in a Kafka topic is corrupted. This often happens when using 3rd party frameworks with Kafka. In addition, Kafka < 0.9 does not have a lock on Log.read() at the consumer read level, but does have a lock on Log.write(). This can lead to a rare race condition as described in KAKFA-2477 [1]. A likely log entry looks like this: ERROR Error processing message, stopping consumer: (kafka.tools.ConsoleConsumer$) kafka.message.InvalidMessageException: Message is corrupt (stored crc = xxxxxxxxxx, computed crc = yyyyyyyyyy Kafka-Tools Kafka stores the offset of each consumer in Zookeeper. To read the offsets, Kafka provides handy tools [2]. But you can also use zkCli.sh, at least to display the consumer and the stored offsets. First we need to find the consumer for a topic (> Kafka 0.9): bin/kafka-consumer-groups.sh --zookeeper management01:2181 --describe --group test Prior to Kafka 0.9, the only way to get this in...

Beyond Ctrl+F - Use LLM's For PDF Analysis

PDFs are everywhere, seemingly indestructible, and present in our daily lives at all thinkable and unthinkable positions. We've all got mountains of them, and even companies shouting about "digital transformation" haven't managed to escape their clutches. Now, I'm a product guy, not a document management guru. But I started thinking: if PDFs are omnipresent in our existence, why not throw some cutting-edge AI at the problem? Maybe Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) could be the answer. Don't get me wrong, PDF search indexes like Solr exist, but they're basically glorified Ctrl+F. They point you to the right file, but don't actually help you understand what's in it. And sure, Microsoft Fabric's got some fancy PDF Q&A stuff, but it's a complex beast with a hefty price tag. That's why I decided to experiment with LLMs and RAG. My idea? An intelligent knowledge base built on top of our existing P...

AI's False Reality: Understanding Hallucination

Artificial Intelligence (AI) has leapfrogged to the poster child of technological innovation, on track to transform industries in a scale similar to the Industrial Revolution of the 1800s. But in this case, as cutting-edge technology, AI presents its own unique challenge, exploiting our human behavior of "love to trust", we as humans face a challenge: AI hallucinations. This phenomenon, where AI models generate outputs that are factually incorrect, misleading, or entirely fabricated, raises complex questions about the reliability and trust of AI models and larger systems. The tendency for AI to hallucinate comes from several interrelated factors. Overfitting – a condition where models become overly specialized to their training data – can lead to confident but wildly inaccurate responses when presented with novel scenarios (Guo et al., 2017). Moreover, biases embedded within datasets shape the models' understanding of the world; if these datasets are flawed or unreprese...