You are doing nothing wrong, unfortunately pg_restore -t
restores only the table, nothing else, regardless of how you created the dump and what is inside the dump itself.
This has been somehow clarified in V12 PostgreSQL docs, that states:
This flag does not behave identically to the -t flag of pg_dump. There is not currently any provision for wild-card matching in pg_restore, nor can you include a schema name within its -t. And, while pg_dump's -t flag will also dump subsidiary objects (such as indexes) of the selected table(s), pg_restore's -t flag does not include such subsidiary objects.
the only way to make sure that restoring a table will carry all the indexes is to address them by name, something like:
pg_restore -U bob -d commerce -t orders -I index1 -I index2 -I index3 > orders.dump
> orders.dump
looks wrong for thepg_restore
command. The input file should be specified as the last argument with the>
– Molton-t tablename
, its constraints and indexes are included in the dump. – Annamarieannamese