I am trying to learn postgresql on linux using the command line interface.
I have added some databases a while back, following some tutorials (which I have since forgot everything I have learned).
Now I want to delete these databases.
I made the assumption that I should be doing this by using psql, the command-line interface to postgresql.
You can see what I have tried in the following command line output, and that none of it has succeeded.
psql (9.5.6)
Type "help" for help.
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
template0 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
(4 rows)
postgres=# dropdb template1
postgres-# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
template0 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
(4 rows)
postgres-# DROP DATABASE template1
postgres-# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
template0 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
(4 rows)
Yes,
DROP DATABASE template1;
And dont forget to backup your database:
to backup: pg_dump name_of_database > name_of_backup_file.bak
to restore: psql empty_database < backup_file.bak
Make sure and end your SQL commands with a semicolon (;)
Try issuing the command
DROP DATABASE template1;
with the semicolon on the end.
If your database contains 'template1' and 'template0' db name. You can use my script below:
UPDATE pg_database SET datistemplate='false' WHERE datname='template1';
DROP DATABASE template1;
Related
I installed it according to the guide on the official website.fabricexplorer But I may be having problems initializing the database.
MacOS
$ cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
$ ./createdb.sh
$ createdb whoami
psql -c '\l'
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------+----------+----------+---------+-------+-----------------------
fabricexplorer | hyy | UTF8 | C | C |
heyueyue | heyueyue | UTF8 | C | C |
postgres | postgres | UTF8 | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres
template0 | heyueyue | UTF8 | C | C | =c/heyueyue +
| | | | | heyueyue=CTc/heyueyue
template1 | heyueyue | UTF8 | C | C | =c/heyueyue +
| | | | | heyueyue=CTc/heyueyue
(5 rows)
heyueyue#heyueyuedeMacBook-Pro test-network % psql $DATABASE_DATABASE -c '\d'
Did not find any relations.
However, there are tables in the database fabricexplorer.
fabricexplorer-# \d
List of relations
Schema | Name | Type | Owner
--------+---------------------------+----------+-------
public | blocks | table | hyy
public | blocks_id_seq | sequence | hyy
public | chaincodes | table | hyy
public | chaincodes_id_seq | sequence | hyy
public | channel | table | hyy
public | channel_id_seq | sequence | hyy
public | orderer | table | hyy
public | orderer_id_seq | sequence | hyy
public | peer | table | hyy
public | peer_id_seq | sequence | hyy
public | peer_ref_chaincode | table | hyy
public | peer_ref_chaincode_id_seq | sequence | hyy
public | peer_ref_channel | table | hyy
public | peer_ref_channel_id_seq | sequence | hyy
public | transactions | table | hyy
public | transactions_id_seq | sequence | hyy
public | users | table | hyy
public | users_id_seq | sequence | hyy
public | write_lock | table | hyy
And I start the service , I can’t login with the correct user and password.
enter image description here
[2022-06-19T16:29:11.875] [DEBUG] PgService - the getRowsBySQlCase select * from channel where name=$1 and channel_genesis_hash=$2 and network_name = $3
Can anybody help?
[Question posted by a user on YugabyteDB Community Slack]
Before dropping a database, first I want to prevent new connections and then drop the existing connections. However, I'm stuck at the first step:
ysqlsh (11.2-YB-2.1.1.0-b0)
yugabyte=# SELECT * FROM pg_database;
datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | datminmxid | dattablespace | datacl
----------------------------+--------+----------+------------+-------------+---------------+--------------+--------------+---------------+--------------+------------+---------------+-------------------------------------
template1 | 10 | 6 | C | en_US.UTF-8 | t | t | -1 | 0 | 0 | 1 | 1663 | {=c/postgres,postgres=CTc/postgres}
template0 | 10 | 6 | C | en_US.UTF-8 | t | f | -1 | 0 | 0 | 1 | 1663 | {=c/postgres,postgres=CTc/postgres}
postgres | 10 | 6 | C | en_US.UTF-8 | f | t | -1 | 0 | 0 | 1 | 1663 |
yugabyte | 10 | 6 | C | en_US.UTF-8 | f | t | -1 | 0 | 0 | 1 | 1663 |
system_platform | 10 | 6 | C | en_US.UTF-8 | f | t | -1 | 0 | 0 | 1 | 1663 |
test_1650530283_52506 | 12462 | 6 | C | en_US.UTF-8 | f | t | -1 | 0 | 0 | 1 | 1663 |
(6 rows)
yugabyte=# UPDATE pg_database SET datallowconn=false WHERE datname = 'test_1650530283_52506';
ERROR: Illegal state: Transaction for catalog table write operation 'pg_database' not found
The described behavior is not a bug. Everything works as expected. It is not recommended to change system tables manually. If it absolutely necessary for some reason user should set the yb_non_ddl_txn_for_sys_tables_allowed GUC variable to true. But user will do this on its own risk.
BTW to disallow connection to DB it is better to use this query instead of changing system table manually:
ALTER DATABASE db WITH ALLOW_CONNECTIONS false;
I am new on Cassandra,
The "hash_key" is different than the "key_desc_id" and I have some issues because of that. Any help with what should i do to fix this issue?
id | name
---------------+----------------------------------------------
1638430493227 | default_cd77c646-cfa4-40b9-9136-5ce83fc586c9
1638430494138 | k2_hash_key
select id,key_desc_id from k2view_cc.entity;
id | key_desc_id
------------------------------------------------------------------+---------------
D54C994CF3CBDA1F70E37853B07388D0C65E824F1BDF3D4F83731513EB8A5399 | 1572012180007
DD5C1E2D9395CA6B1B5ABDF87C03392493F03328F37830045749EA1AE725AF91 | 1572012180007
3467EA971FC018EB561F07F57547CF17E618B76D93B4F8471280C3CF8FB32D58 | 1572012180007
EB4A8D07DF41EDDB49D530BE39B8D8850AFF7D108787CE1EF46EE27D00E99E57 | 1572012180007
AB92F2C90E3337EED0B68B2EC1B56B6FA45A9461C711406B7ED01BE7B29F75EE | 1572012180007
9BC6D9862B68C8AE810CC1A00BFF87ADF6A95A262C98987780807D458682330C | 1572012180007
AFE8B598517CCFC09E71DF10417DAC3B1002731F43334CA6872BC4CEA9A07D75 | 1572012180007
Is there a way to determine if the delete operation actually deleted a partition if the partition existed? I am running the following cql queries. I was hoping that I'll get an error when I'll specify an invalid partition but I don't
cqlsh:mypartition> select * from users;
bucket | email | authprovider | firstname | lastname | confirmed | hasher | id | password | salt
--------+---------------+--------------+-----------+----------+-----------+------------+--------------------------------------+--------------+------
1 | test#test.com | credentials | fn | ln | False | someHasher | 11111111-1111-1111-1111-111111111111 | somePassword |
(1 rows)
cqlsh:mypartition> DELETE FROM users WHERE bucket=1 AND email='test1#test.com';
cqlsh:mypartition> select * from users;
bucket | email | authprovider | firstname | lastname | confirmed | hasher | id | password | salt
--------+---------------+--------------+-----------+----------+-----------+------------+--------------------------------------+--------------+------
1 | test#test.com | credentials | fn | ln | False | someHasher | 11111111-1111-1111-1111-111111111111 | somePassword |
(1 rows)
cqlsh:mypartition> DELETE FROM users WHERE bucket=1 AND email='test#test.com';
cqlsh:codingjedi> select * from users;
bucket | email | authprovider | firstname | lastname | confirmed | hasher | id | password | salt
--------+-------+--------------+-----------+----------+-----------+--------+----+----------+------
(0 rows)
cqlsh:codingjedi>
You can't. Deletes are just writes, and Cassandra sorts it out in compaction.
I have a create a database using the following query:
create database sample;
but when I try to access the database Psequel GUI or my nodejs server, I keep getting this error:
database "sample" does not exist
Database sample is clearly available as shown below.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
reveal | postgres | UTF8 | C | C |
revealdb | postgres | UTF8 | C | C |
sampl | postgres | UTF8 | C | C |
sample | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres