I'm trying to programatically generate code using jooq 3.12.3 with the following code, but the program runs successfully and no code is generated.
Configuration configuration =
new Configuration()
.withJdbc(
new Jdbc()
.withDriver("org.postgresql.Driver")
.withUrl("jdbc:postgresql://127.0.0.1:6666/postgres")
.withUser("<username>")
.withPassword("<correct password>"))
.withGenerator(
new Generator()
.withDatabase(
new Database()
.withName("org.jooq.meta.postgres.PostgresDatabase")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("public"))
.withGenerate(
new Generate()
.withDaos(true)
.withDeprecated(false)
.withImmutablePojos(false)
.withPojosEqualsAndHashCode(true)
.withValidationAnnotations(true)
.withVarargSetters(false))
.withTarget(
new Target()
.withPackageName("com.package.data.jooq")
.withDirectory("src/main/java")));
GenerationTool.generate(configuration);
Some debugging info
\dt
List of relations
Schema | Name | Type | Owner
--------+-------------------+-------+----------
public | django_migrations | table | postgres
public | table1 | table | postgres
public | table2 | table | postgres
,
\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+-------------------+----------+------------+------------+-----------------------------------------
cloudsqladmin | cloudsqladmin | UTF8 | en_US.UTF8 | en_US.UTF8 |
postgres | cloudsqlsuperuser | UTF8 | en_US.UTF8 | en_US.UTF8 |
,
SELECT table_catalog, table_schema, table_name
FROM information_schema.tables;
doesn't show public under table_schema
What could be the problem?
The problem was with permissions..
GRANT SELECT ON TABLE public.table1 TO user;
GRANT SELECT ON TABLE public.table2 TO user;
Solved the problem. After this the tables started showing up in
SELECT table_catalog, table_schema, table_name
FROM information_schema.tables;
Related
I am using postgresql 15
and I tried running these
grant all privileges on database my_database to my_database_user;
grant all privileges on all tables in schema public to my_database_user;
grant all privileges on all sequences in schema public to my_database_user;
grant all privileges on all functions in schema public to my_database_user;
but when I run
php artisan migrate --seed
I got
SQLSTATE[42501]: Insufficient privilege: 7 ERROR: permission denied for schema public at character 14 (SQL: create table "migrations" ("id" serial primary key not null, "migration" varchar(255) not null, "batch" integer not null))
What I am missing?
I do make sure .env has correct credentials
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=my_database
DB_USERNAME=my_database_user
DB_PASSWORD=password
Checking that i did
postgres=# \du my_database_user
List of roles
Role name | Attributes | Member of
-------------+------------+-----------
my_database_user | | {}
and
postgres=# SELECT * FROM pg_roles;
rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig | oid
---------------------------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
my_database_user | f | t | f | f | t | f | -1 | ******** | | f | | 16389
You are missing permissions on the schema:
GRANT CREATE ON SCHEMA public TO my_database_user;
You are probably using PostgreSQL v15 or higher. The default permissions on the public schema have changed in v15. Before, the insecure default was to allow everyone (PUBLIC) to create objects in schema public. Now only the database owner can do that, unless you grant extra privileges.
I took postgresql dump and restore it in another db. I am trying to change the permission of the table in the secondary db. But I am not change the permission can't evn view individual table.
Whenever I list all the tables in a Scheme I can get the results but when i search for individual tables getting below error.
select \* from pg_tables where schemaname='testing';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
\------------+-----------------+------------+------------+------------+----------+-------------+-------------
testing | chatting | postgres | | t | f | t | f
testing | report | postgres | | t | f | f | f
select chatting from pg_tables where schemaname='testing';
ERROR: column "chatting" does not exist
LINE 1: select channel from pg_tables where schemaname='testing';
Can someone help me on this? I would like to change the owner of all the tables in this schema to a different user.
Note: I haven't create the tables, it is part of the pg_dump.
The query that you should run is
select * from pg_tables where schemaname='testing' and tablename = 'chatting';
If I log into postgres and switch to the postgres database, when I check for tables with this command I get nothing back:
postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=# \dt+
Did not find any relations.
However if I do a select on the DB tables I do see that the tables are there:
postgres=# SELECT *
postgres-# FROM pg_catalog.pg_tables
postgres-# WHERE schemaname != 'pg_catalog' AND
postgres-# schemaname != 'information_schema';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
------------+----------------+------------+------------+------------+----------+-------------+-------------
pgagent | pga_jobclass | postgres | | t | f | t | f
pgagent | pga_job | postgres | | t | f | t | f
pgagent | pga_jobagent | postgres | | t | f | t | f
pgagent | pga_jobstep | postgres | | t | f | t | f
pgagent | pga_schedule | postgres | | t | f | t | f
pgagent | pga_exception | postgres | | t | f | t | f
pgagent | pga_joblog | postgres | | t | f | t | f
pgagent | pga_jobsteplog | postgres | | t | f | t | f
(8 rows)
Why do I get nothing when I use \dt+ but I can see the tables using a select statement?
I think that this will help LINK
\d [NAME] describe table, index, sequence, or view
\d{t|i|s|v|S} [PATTERN] ("+" detail) list tables/indexes/sequences/views/system tables
\da [PATTERN] list aggregate functions
\db [PATTERN] list tablespaces (add "+" for more detail)
use \dt+ *
the * to match all as the command needs a pattern
The reason is that the pgagent schema is not on your search_path. \dt will only show those tables that you can access without schema qualification.
This question already has answers here:
In psql, why do some commands have no effect?
(2 answers)
Closed 2 years ago.
I have been trying to create a table in PostgreSQL but have been getting the following error when I try to list tables with \dt - Did not find any relations.
I used the following create statement - create table jobs( id serial primary key, title text, link text, company text) inside a database named scrape
If I use \dt *.* then a list of tables appear which seem to built-ins -
List of relations
Schema | Name | Type | Owner
--------------------+-------------------------+-------+----------
information_schema | sql_features | table | postgres
information_schema | sql_implementation_info | table | postgres
information_schema | sql_languages | table | postgres
information_schema | sql_packages | table | postgres
information_schema | sql_parts | table | postgres
information_schema | sql_sizing | table | postgres
information_schema | sql_sizing_profiles | table | postgres
pg_catalog | pg_aggregate | table | postgres
pg_catalog | pg_am | table | postgres
pg_catalog | pg_amop | table | postgres
pg_catalog | pg_amproc | table | postgres
pg_catalog | pg_attrdef | table | postgres
pg_catalog | pg_attribute | table | postgres
pg_catalog | pg_auth_members | table | postgres
pg_catalog | pg_authid | table | postgres
pg_catalog | pg_cast | table | postgres
pg_catalog | pg_class | table | postgres
pg_catalog | pg_collation | table | postgres
pg_catalog | pg_constraint | table | postgres
pg_catalog | pg_conversion | table | postgres
pg_catalog | pg_database | table | postgres
pg_catalog | pg_db_role_setting | table | postgres
pg_catalog | pg_default_acl | table | postgres
pg_catalog | pg_depend | table | postgres
pg_catalog | pg_description | table | postgres
pg_catalog | pg_enum | table | postgres
pg_catalog | pg_event_trigger | table | postgres
pg_catalog | pg_extension | table | postgres
pg_catalog | pg_foreign_data_wrapper | table | postgres
pg_catalog | pg_foreign_server | table | postgres
pg_catalog | pg_foreign_table | table | postgres
pg_catalog | pg_index | table | postgres
pg_catalog | pg_inherits | table | postgres
pg_catalog | pg_init_privs | table | postgres
pg_catalog | pg_language | table | postgres
pg_catalog | pg_largeobject | table | postgres
pg_catalog | pg_largeobject_metadata | table | postgres
pg_catalog | pg_namespace | table | postgres
pg_catalog | pg_opclass | table | postgres
pg_catalog | pg_operator | table | postgres
pg_catalog | pg_opfamily | table | postgres
pg_catalog | pg_partitioned_table | table | postgres
pg_catalog | pg_pltemplate | table | postgres
pg_catalog | pg_policy | table | postgres
pg_catalog | pg_proc | table | postgres
pg_catalog | pg_publication | table | postgres
pg_catalog | pg_publication_rel | table | postgres
pg_catalog | pg_range | table | postgres
pg_catalog | pg_replication_origin | table | postgres
pg_catalog | pg_rewrite | table | postgres
pg_catalog | pg_seclabel | table | postgres
pg_catalog | pg_sequence | table | postgres
pg_catalog | pg_shdepend | table | postgres
pg_catalog | pg_shdescription | table | postgres
pg_catalog | pg_shseclabel | table | postgres
pg_catalog | pg_statistic | table | postgres
pg_catalog | pg_statistic_ext | table | postgres
pg_catalog | pg_statistic_ext_data | table | postgres
pg_catalog | pg_subscription | table | postgres
pg_catalog | pg_subscription_rel | table | postgres
pg_catalog | pg_tablespace | table | postgres
pg_catalog | pg_transform | table | postgres
pg_catalog | pg_trigger | table | postgres
pg_catalog | pg_ts_config | table | postgres
pg_catalog | pg_ts_config_map | table | postgres
pg_catalog | pg_ts_dict | table | postgres
pg_catalog | pg_ts_parser | table | postgres
pg_catalog | pg_ts_template | table | postgres
pg_catalog | pg_type | table | postgres
pg_catalog | pg_user_mapping | table | postgres
I also checked the schemas whether they were public or not -
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(1 row)
If it helps I am also including the users here -
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
arif | Superuser, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
I also checked the databases -
scrape-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
arif | arif | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
scrape | arif | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
You got confused by the semicolons in psql. This happens to everybody in the beginning.
A statement is sent to the server only when psql has received the semicolon that terminates the statement. Otherwise, all you get is a slightly changed prompt that indicates that psql is waiting for a continuation line.
So if you enter
CREATE TABLE mytab (x integer)
without a semicolon, nothing much happens yet.
Then you realize that you forgot the terminating semicolon, and you enter
CREATE TABLE mytab (x integer);
Now psql will consider both lines a single statement and send it to the server, which results in the error message you see.
When in doubt, you can always press Ctrl+C to clear the state and discard the statement buffer.
I'm still new to psql and I've stumbled upon a problem.
I have a user admin which I've granted all privileges on database mywebsite
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+-----------------------
mywebsite | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | admin=CTc/postgres
postgres | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 |
template0 | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
Here's the list of roles
mywebsite=# \du
admin | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
mywebsite=# \dn+
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
mywebsite=# \d
No relations found.|
I tried to check if the database is empty
mywebsite=# select count(*)
mywebsite-# from pg_class c
mywebsite-# join pg_namespace s on s.oid = c.relnamespace
mywebsite-# where s.nspname not in ('pg_catalog', 'information_schema')
mywebsite-# and s.nspname not like 'pg_temp%'
mywebsite-# ;
count
-------
36
(1 row)
This counts the number of tables that are not default Postgres tables.
So I don't know why it outputs "No Relations found"
This counts the number of tables that are not default Postgres tables.
Pretty sure it does not. You forgot about TOAST tables. I'm getting 40 on my somewhat fresh install of 10.1.
But this should count number of tables, sequences and a few other relations:
select count(*)
from pg_class c
join pg_namespace s on s.oid = c.relnamespace
where s.nspname not in ('pg_catalog', 'information_schema', 'pg_toast')
and s.nspname not like 'pg_temp%'